Java 需要帮助理解APDU响应吗
我使用ACR122读卡器已经有一段时间了,读Mifare 1K或Mifare超轻NFC卡都没有问题 将读卡器升级到最新版本(ACR1251)后,我的程序无法从Mifare 1K卡读取UID 这是我用来阅读的片段:Java 需要帮助理解APDU响应吗,java,nfc,apdu,Java,Nfc,Apdu,我使用ACR122读卡器已经有一段时间了,读Mifare 1K或Mifare超轻NFC卡都没有问题 将读卡器升级到最新版本(ACR1251)后,我的程序无法从Mifare 1K卡读取UID 这是我用来阅读的片段: CardTerminal terminal = terminalWithCardPresent.get(0); terminal.waitForCardPresent(0); Card card = terminal.connect("T=1"); if (card != null)
CardTerminal terminal = terminalWithCardPresent.get(0);
terminal.waitForCardPresent(0);
Card card = terminal.connect("T=1");
if (card != null) {
CommandAPDU command = new CommandAPDU((byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x07);
CardChannel channel = card.getBasicChannel();
ResponseAPDU response = channel.transmit(command);
StringBuilder sb = new StringBuilder();
if (response.getSW1() == 0x90 && response.getSW2() == 0x00) {
byte[] data = response.getData();
String code = decoder.apply(data);
sb.append(code);
}
cardIdRead.recieve(sb.toString());
}
terminal.waitForCardAbsent(0);
使用新版rad reader:
- 函数的作用是:返回98
- 而getSW2()返回130
我曾尝试在网络和读卡器文档中搜索响应代码的解释,但没有成功。其他任何人都有类似的问题,并且知道如何从sw1 sw2 98 130上的卡返回读取UID?将SW
98 130
转换为hex GIVED'6282'
。从中,它意味着“由于首先遇到文件结尾,因此可以读取的字节数少于Le参数指定的字节数。”
“FF CA”
记录在中,但在中找不到。根据ACR122U文档,Le应该是'00'
,而不是'07'
我建议尝试发送APDU'FFCA000000'
,如果失败,尝试发送'FFCA0000XX'
(XX从'01'到'06')。对于JAVASE用途(Ultralight nfc卡),您可以按照以下链接和代码进行操作
对于读取UID,命令为:
baReadUID = new byte[] { (byte) 0xFF, (byte) 0xCA, (byte) 0x00,
(byte) 0x00, (byte) 0x00 };
对于从Specefic块读取(此处读取第04页至第07页),命令为:
read_four_to_seven = new byte[]{(byte) 0xFF, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x05, (byte) 0x0D4, (byte) 0x40, (byte) 0x01,
(byte) 0x30, (byte) 0x04, (byte) 0x07 };
要写入第04页:
Write_Page_Four = new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x15, (byte) 0xD4, (byte) 0x40,
(byte) 0x01, (byte) 0xA0, (byte) 0x04, (byte) 0x4D,
(byte) 0x65, (byte) 0x73, (byte) 0x75, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00 };