3
我想生成卡與終端之間的安全通道。這是我的代碼:生成卡與終端之間的安全通道
final static byte INIT_UPDATE = (byte) 0x50;
final static byte EXT_AUTHENTICATE = (byte) 0x82;
SecureChannel sc;
public void process(APDU apdu) throws ISOException {
if (selectingApplet()) {
return;
}
byte[] buffer = apdu.getBuffer();
short inlength = 0;
try
{
switch (buffer[ISO7816.OFFSET_INS]) {
case INIT_UPDATE:
case EXT_AUTHENTICATE:
makeSecureChannel(apdu);
break;
}
catch (CryptoException e)
{
short r = e.getReason();
ISOException.throwIt(r);
}
}
private void makeSecureChannel(APDU apdu)
{
byte[] buf = apdu.getBuffer();
byte cla = buf[ISO7816.OFFSET_CLA];
byte ins = buf[ISO7816.OFFSET_INS];
try
{
apdu.setIncomingAndReceive();
if(ins == INIT_UPDATE)
{
sc = GPSystem.getSecureChannel();
}
short len = sc.processSecurity(apdu);
apdu.setOutgoing();
apdu.setOutgoingLength(len);
apdu.sendBytes(ISO7816.OFFSET_CDATA, (short) len);
}
catch(APDUException ex1)
{
ISOException.throwIt(ex1.getReason());
}
}
當我發送命令80 50 20 00 08 01 15 6A 2A F5 64 87 CF
我得到錯誤6a88
,當我發送命令00 50 20 00 08 01 15 6A 2A F5 64 87 CF
我得到錯誤6e00
。 每個人都可以幫助我嗎?
您可以將錯誤本地化爲特定的代碼行嗎?你能調試嗎?您確定您的卡支持此全球平臺API調用嗎? –
您是否在發送APDU命令之前選擇了您的小程序?你的鑰匙版本是否設有鑰匙== 0x20?如果不是,則用0x00替換0x20。 – Abraham