【问题标题】:Read NFC Mifare Ultralight cards with javax.smartcardio使用 javax.smartcardio 读取 NFC Mifare Ultralight 卡
【发布时间】: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


    【解决方案1】:

    第二种情况下的 ATR 3B80800101(它不起作用)表示读卡器没有检测到(或没有正确检测到)卡。 ACR1252U 似乎只模拟此 ATR 以允许通过 PC/SC API(例如javax.smartcardio)进行连接,即使实际上没有卡存在。如果读卡器明确指出不存在卡,这将是不可能的。

    检查读卡器是否检测到您的卡(并将其识别为 MIFARE Ultralight)的更可靠方法是根据 PC/SC 规范解析 ATR(请参阅非接触式存储卡的 ATR 部分):

    3B 8F 80 01 80 4F 0C A000000306 03 0003 00000000 68 | | | | | | | \--> RR = 保留供将来使用 | | \-------> NN = MIFARE 超轻 | \----------> SS = ISO 14443 A 型第 3 部分 \---------------------> PC/SC RID

    【讨论】:

    • 感谢您的回答!为什么您认为“读卡器没有检测到(或没有正确检测到)卡”?我的 NFC 卡有可能(几乎)死了吗?即使我再次尝试断开/连接,结果也是一样的..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-10
    相关资源
    最近更新 更多