smartcard - 如果缓冲区大小 >7,则 Javacard 错误 APDU
问题描述
我正在尝试使用字节数组设置 CommandAPDU 缓冲区。但是,如果长度>7,则会引发以下错误:
线程“主”java.lang.IllegalArgumentException 中的异常:APDU 无效:长度 = 8,b1 = 1 在 javax.smartcardio.CommandAPDU.parse(CommandAPDU.java:318) 在 javax.smartcardio.CommandAPDU.(CommandAPDU.java:98 ) 在终端.Main.main(Main.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, int p1, 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);
祝你好运!
推荐阅读
- c# - 我应该关心游戏中的课程数量吗?
- node.js - Python将带有socket.io的opencv img发送到Nodejs
- ios - 带有 switch 语句的 SwiftUI 动画
- javascript - Azure 存储 blob 库将 blob 下载到本地计算机
- crc - 我如何为这个协议建模 CRC
- javascript - Stripe React 成功响应后如何重定向到另一个页面?
- python - Python多处理:超过超时后通过参数终止进程
- winforms - 嵌套的 DataGridView 控件似乎总是优先考虑箭头键导航的父 DGV,而不是实际焦点所在的 DGV
- vba - VBA:类模块(DblClick 事件)
- python - Django:如何在会话中动态存储用户数据?