我有一个Java卡,并编写了一个发送APDU到Java卡的小代码。当我发送Init_Update命令时,我会收到0x6985的响应,类似于:
我有一张java卡并写了发送APDU到java卡的代码。在这里当我发送Init_Update命令时,我收到类似于0x6985的响应:
CMD -> 80 50 00 00 08 11 22 33 44 55 66 77 88
RES <- 6985
但当我使用其他工具发送此命令时,它会给出所需的结果,例如:
Transmit: 80 50 00 00 08 []
11 22 33 44 55 66 77 88 ."3DUfw.
Card answered: 61 1C
我的Java代码在我拥有的其他Java卡上能够正常工作。有人可以告诉我这种不同行为的原因吗?
// full java code
public static void main(String[] args) {
// TODO code application logic here
try
{
factory = TerminalFactory.getDefault();
terminals = factory.terminals().list();
terminal = terminals.get(0);
card = terminal.connect("*");
channel =card.getBasicChannel();
CommandAPDU cmdAPDU;
ResponseAPDU response;
byte[] select_isd = {(byte) 0x00,(byte) 0xA4,(byte) 0x04,(byte) 0x00,(byte) 0x08,(byte) 0xA0,(byte) 0x00,
(byte) 0x00,(byte) 0x00,(byte) 0x03,(byte) 0x00,(byte) 0x00,(byte) 0x00 };
cmdAPDU = new CommandAPDU(select_isd);
response = channel.transmit(cmdAPDU);
byte[] INIT_UPDATE = {(byte) 0x80,(byte) 0x50,(byte) 0x00,(byte) 0x00,(byte) 0x08,(byte) 0x11,(byte) 0x22,
(byte) 0x33,(byte) 0x44,(byte) 0x55,(byte) 0x66,(byte) 0x77,(byte) 0x88 };
cmdAPDU = new CommandAPDU(INIT_UPDATE);
response = channel.transmit(cmdAPDU);
}
catch( Exception ex)
{
}
}
其他工具日志看起来像:
Card opened
12 bytes ATR received:
3B 68 00 00 00 73 C8 40 00 00 90 00
Transmit: 00 A4 04 00 08 [SELECT FILE]
A0 00 00 00 03 00 00 00 ........
Card answered: 61 12
Transmit: 00 C0 00 00 12 [GET RESPONSE]
Card answered: 90 00
6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 o..............e
01 FF ..
Transmit: 80 50 00 00 08 []
11 22 33 44 55 66 77 88 ."3DUfw.
Card answered: 61 1C
但是当我运行我的Java代码时,INIT_UPDATE命令返回6985。
如果需要其他信息,请告诉我。
==新添加的内容=== 我尝试在JCOP shell中运行我的脚本,我的脚本类似于:
/mode trace=on
/terminal
/atr
/send 80CAA08D05
/send 802E000014B555C94B0B2368B4840201808502032288020060
/send 80D8000000
/atr
/send 80500000081122334455667788
我已经得到了所需的结果。我试着在Java中实现它,我的新Java代码看起来像:
=====新更新的JAVA代码===factory = TerminalFactory.getDefault();
terminals = factory.terminals().list();
terminal = terminals.get(0);
card = terminal.connect("*");
channel =card.getBasicChannel();
CommandAPDU cmdAPDU;
ResponseAPDU response;
byte[] x = { (byte) 0x80, (byte) 0xCA, (byte) 0xA0,(byte) 0x8D,(byte)0x05};
byte[] y = { remove command for security reasons};
byte[] z = { (byte) 0x80, (byte) 0xD8, (byte) 0x00, (byte) 0x00, (byte) 0x00}; // it set default key
cmdAPDU = new CommandAPDU(x);
response = channel.transmit(cmdAPDU);
System.out.println(response.toString());
cmdAPDU = new CommandAPDU(y);
response = channel.transmit(cmdAPDU);
System.out.println(response.toString());
cmdAPDU = new CommandAPDU(z);
response = channel.transmit(cmdAPDU);
System.out.println(response.toString());
card.disconnect(true);
card = terminal.connect("*");
channel =card.getBasicChannel();
byte[] INIT_UPDATE = {(byte) 0x80,(byte) 0x50,(byte) 0x00,(byte) 0x00,(byte) 0x08,(byte) 0x11,(byte) 0x22,(byte) 0x33,(byte) 0x44,(byte) 0x55,(byte) 0x66,(byte) 0x77,(byte) 0x88 };
cmdAPDU = new CommandAPDU(INIT_UPDATE);
response = channel.transmit(cmdAPDU);