【发布时间】:2017-03-14 06:42:14
【问题描述】:
我尝试使用 ACR1252U 和 javax.smartcardio Java 库读取 NFC Mifare Ultralight 卡(第 4 页):
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
CardTerminal terminal = terminals.get(0);
System.out.println("Waiting for a card..");
if (terminal == null)
return;
terminal.waitForCardPresent(0);
Card card = terminal.connect("T=1");
System.out.println("Card: " + card);
System.out.println("ATR: " + bytesToHex(card.getATR().getBytes()));
System.out.println("Protocol: " + card.getProtocol());
CardChannel channel = card.getBasicChannel();
CommandAPDU command = new CommandAPDU(new byte[]{(byte) 0xFF,
(byte) 0xB0, (byte) 0x00, (byte) 0x04, (byte) 0x04});
ResponseAPDU response = channel.transmit(command);
if (response.getSW1() == 0x90) {
// success command
byte[] data = response.getData();
System.out.println(new String(data));
}
有时有效,有时无效(使用同一张卡)
当阅读有效时,我得到这些值:
- ATR = 0x3B8F8001804F0CA0000003060300030000000068
- SW1 = 0x90
- SW2 = 0x00
当它不起作用时,我会得到这些:
- ATR = 0x3B80800101
- SW1 = 0x63
- SW2 = 0x00
知道我做错了什么吗?
【问题讨论】:
标签: java nfc smartcard mifare apdu