如果缓冲区大小为 >7,则 Java 卡错误 APDU



我正在尝试使用字节数组设置CommandAPDU缓冲区。但是,如果长度为>7,则会引发以下错误:

线程"main"中的异常 java.lang.IllegalArgumentException: 无效 APDU:长度=8,b1=1 javax.smartcardio.CommandAPDU.parse(CommandAPDU.java:318( at javax.smartcardio.CommandAPDU.(CommandAPDU.java:98( at 终端。主要(主要.java:78(

我的代码:

byte terminal = 0x00;
byte instruction = 0x01;
byte [] msg = {0x01,0x00,0x01,0x00};
byte [] fullmsg = new byte[msg.length + 4];
System.arraycopy(new byte []{terminal}, 0, fullmsg, 0, 1);
System.arraycopy(new byte [] {instruction}, 0, fullmsg, 1, 1);
System.arraycopy(new byte [] {0,0}, 0, fullmsg, 2, 2);
System.arraycopy(msg, 0, fullmsg, 4, msg.length);
CommandAPDU cmdapdu = new CommandAPDU(fullmsg);

有人可以帮助我吗?

考虑使用 CommandAPDU(int cla, int ins, int p1, int p2, byte[] data((如果您不希望从卡返回任何数据 - 即命令是 ISO-7816 案例 3(或 CommandAPDU(int cla, int ins, intp1, int p2, byte[] data, int ne((如果您希望从卡返回一些数据 - 即命令是 ISO-7816 案例 4(来创建您的 CommandAPDU 对象。

有关命令 APDU 格式的更多详细信息(此处部分可用(,请参阅 ISO 7816-3 第 12.1 节"应用程序协议数据单元"。

例如:

CommandAPDU cmdapdu = new CommandAPDU(terminal, instruction, 0, 0, msg);

或(随意将 256 替换为任何其他预期的响应数据长度(:

CommandAPDU cmdapdu = new CommandAPDU(terminal, instruction, 0, 0, msg, 256);

祝你好运!

最新更新