输入80E3,可执行算法正确性检验,验证通过,对len=38Bytes明文加密结果符合预期、解密结果符合输入;
输入80E2,可写入密钥到flash,若算法类型、key id, key版本一致,就写入,已满就报错,无记录就写入新记录; 输入80CA,可执行伪位置加密,原封不动将输入的data返回回来。
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.cscn;
|
||||
|
||||
import javacard.framework.APDU;
|
||||
@@ -16,20 +13,25 @@ import org.globalplatform.SecureChannel;
|
||||
*/
|
||||
public class XwSecurity extends Applet {
|
||||
|
||||
public static final byte INS_PROCESS_DATA = (byte)0xCA;
|
||||
public static final byte INS_PROCESS_DATA = (byte)0xE3;
|
||||
|
||||
public static final byte INS_STORE_DATA = (byte)0xE2;
|
||||
public static final byte INS_LOCATION_ENCRYPT = (byte)0xCA;
|
||||
|
||||
public static final byte INS_INITIAL_UPDATE = (byte)0x50;
|
||||
public static final byte INS_STORE_KEY = (byte)0xE2;
|
||||
|
||||
// public static final byte INS_INITIAL_UPDATE = (byte)0x50;
|
||||
//
|
||||
// public static final byte INS_EXTERNAL_AUTH = (byte)0x82;
|
||||
|
||||
public static final byte INS_EXTERNAL_AUTH = (byte)0x82;
|
||||
|
||||
private Method method;
|
||||
|
||||
|
||||
byte[] key_store_byte;
|
||||
|
||||
public XwSecurity(byte[] bArray, short bOffset, byte bLength) {
|
||||
// TODO Auto-generated constructor stub
|
||||
method = new Method();
|
||||
|
||||
key_store_byte = new byte[80];
|
||||
|
||||
register(bArray, (short)(bOffset + 1), bArray[bOffset]);
|
||||
}
|
||||
|
||||
@@ -50,33 +52,44 @@ public class XwSecurity extends Applet {
|
||||
if(method == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
byte[] buf = apdu.getBuffer();
|
||||
short off = ISO7816.OFFSET_CDATA;
|
||||
short len = apdu.setIncomingAndReceive();
|
||||
|
||||
switch (buf[ISO7816.OFFSET_INS])
|
||||
{
|
||||
case INS_INITIAL_UPDATE:
|
||||
SecureChannel sc = GPSystem.getSecureChannel();
|
||||
sc.processSecurity(apdu);
|
||||
break;
|
||||
|
||||
case INS_EXTERNAL_AUTH:
|
||||
sc = GPSystem.getSecureChannel();
|
||||
sc.processSecurity(apdu);
|
||||
break;
|
||||
|
||||
case INS_PROCESS_DATA:
|
||||
method.processData(apdu);
|
||||
break;
|
||||
|
||||
case INS_STORE_DATA:
|
||||
method.updateKey(apdu);
|
||||
break;
|
||||
|
||||
default:
|
||||
// good practice: If you don't know the INStruction, say so:
|
||||
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
||||
// case INS_INITIAL_UPDATE:
|
||||
// SecureChannel sc = GPSystem.getSecureChannel();
|
||||
// sc.processSecurity(apdu);
|
||||
// break;
|
||||
//
|
||||
// case INS_EXTERNAL_AUTH:
|
||||
// sc = GPSystem.getSecureChannel();
|
||||
// sc.processSecurity(apdu);
|
||||
// break;
|
||||
|
||||
|
||||
case INS_PROCESS_DATA:
|
||||
method.processData(apdu);
|
||||
break;
|
||||
|
||||
|
||||
case INS_LOCATION_ENCRYPT:
|
||||
len = method.processDataFake(buf, off, len, key_store_byte);
|
||||
apdu.setOutgoingAndSend(off, len);
|
||||
break;
|
||||
|
||||
case INS_STORE_KEY:
|
||||
len = method.updateKey(buf, off, len, key_store_byte);
|
||||
apdu.setOutgoingAndSend(off, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
// good practice: If you don't know the INStruction, say so:
|
||||
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user