我正在使用 ACS AET65 读卡器尝试将字符串存储到智能卡中,然后将其读回。我正在使用智能卡 IO API,并且能够获取终端并与卡连接。但是,我一直在阅读 ISO 7816 规范,我真的迷路了。
我需要做的就是将一个 3K 字符串写入卡,然后将其读回。而已。根据我的研究,似乎这些卡上应该安装了小程序,但我确信必须有一种方法可以将纯字节数组写入其中并将其取回。
我不知道如何为此构建 APDU 命令。我尝试了 READ BINARY、WRITE BINARY、ERASE BINARY,但我肯定做错了什么。它总是返回 0x6E 和 0x00 作为响应的 SW1 和 SW2 字节,这意味着错误。这是我使用小字符串向小程序发送测试命令的部分的片段:
Card card = cardTerminal.connect("*");
card.beginExclusive();
System.out.println("Card protocol: "+card.getProtocol());
CardChannel channel = card.getBasicChannel();
String jsonStr = "small test string";
byte[] totalData = new byte[256];
byte[] data = jsonStr.getBytes();
System.arraycopy(data, 0, totalData, 0, data.length);
CommandAPDU eraseCommand = new CommandAPDU(0x00, 0x0E, 0x00, 0x00, data, 0x00);
ResponseAPDU eraseCommandResponse = channel.transmit(eraseCommand);
int eSw1 = eraseCommandResponse.getSW1();
int eSw2 = eraseCommandResponse.getSW2();
// returns 6E00, error
System.out.println("Erase Response SW1: " + toHexString(eSw1) + " and SW2: " + toHexString(eSw2));
CommandAPDU writeCommand = new CommandAPDU(0x00, 0xD0, 0x00, 0x00, data, 0x00);
ResponseAPDU commandResponse = channel.transmit(writeCommand);
int sw1 = commandResponse.getSW1();
int sw2 = commandResponse.getSW2();
// returns 6E00, error
System.out.println("Write Response SW1: " + toHexString(sw1) + " and SW2: " + toHexString(sw2));
byte[] totalReadData = new byte[255];
CommandAPDU readCommand = new CommandAPDU(0x00, 0xB0, 0x00, 0x00, totalReadData, 0);
ResponseAPDU readCommandResponse = channel.transmit(readCommand);
int rSw1 = readCommandResponse.getSW1();
int rSw2 = readCommandResponse.getSW2();
// returns 6E00, error
System.out.println("Read Response SW1: " + toHexString(rSw1) + " and SW2: " + toHexString(rSw2));
byte[] totalReadData2 = readCommandResponse.getData();
// always returns an empty array
System.out.println("Total data read: "+totalReadData2.length);
card.endExclusive();
如何使用智能卡 API 完成此操作?
谢谢!!爱德华多