50,527
社区成员
发帖
与我相关
我的任务
分享
package card1;
import javacard.framework.*;
import javacard.security.*;
import javacardx.annotations.*;
//import static card1.card1Strings.*;
/**
* Applet class
*
* @author <user>
*/
@StringPool(value = {
@StringDef(name = "Package", value = "card1"),
@StringDef(name = "AppletName", value = "card1")},
// Insert your strings here
name = "card1Strings")
public class card1 extends Applet {
final static byte Card_CLA =(byte)0x80;
final static byte RANDOM =(byte)0x30;
byte[] Random;
public static void install(byte[] bArray, short bOffset, byte bLength) {
new card1();
}
protected card1() {
register();
}
@Override
public void process(APDU apdu) throws ISOException {
//Insert your code here
byte[] buffer=apdu.getBuffer();
apdu.setIncomingAndReceive();
if(apdu.isISOInterindustryCLA()) {
if(buffer[ISO7816.OFFSET_INS]==(byte)(0xa4)) {
return;
}
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
switch(buffer[ISO7816.OFFSET_INS]) {
//随机数生成0x30
case RANDOM :
if(Random==null) Random=JCSystem.makeTransientByteArray((short)8, JCSystem.CLEAR_ON_DESELECT);
//ISOException.throwIt(ISO7816.SW_CORRECT_LENGTH_00);//自设断点,.此语句在这一行时运行结果能返回0x6c00,但再往下挪一行SW码就变成0x6f00
RandomData data=RandomData.getInstance((byte)RandomData.ALG_PSEUDO_RANDOM);
data.setSeed(Random, (short)0, (short)8);//seed
data.generateData(Random, (short)0, (short)8);
Util.arrayCopyNonAtomic(Random, (short)0, buffer, (short)0, (short)8);
apdu.setOutgoingAndSend((short)0, (short)8);
break;
……
}
}
//randomdata
0x80 0x30 0x00 0x00 0x00 0x7f;//C-APDU
APDU|CLA: 80, INS: 30, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 6f, SW2: 00