我正在使用 javax.smartcardio
包使用 Java 为智能卡编写一个小型应用程序,并且我在 ATR(重置答案)方面遇到了一些问题。 card.getATR()
方法不会重置卡。它返回 ATR 字节,但不会将卡返回到 MF 状态。
这是我的例子:
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
// get the first terminal
CardTerminal terminal = terminals.get(0);
// establish a connection with the card
Card card = terminal.connect("T=0");
ATR atr = card.getATR(); //atr.getBytes() <- correct
CardChannel channel = card.getBasicChannel();
ResponseAPDU r;
// STEP 1. select file in MF
r = channel.transmit(new CommandAPDU(new byte[]{0,(byte)0xA4,(byte)0x02,(byte)0x0C,(byte)0x02,0,(byte)0x02,0}));
// r.getBytes() == 90 00 <- correct
// STEP 2. select DF
r = channel.transmit(new CommandAPDU(new byte[]{0,(byte)0xA4,(byte)0x04,(byte)0x0C,(byte)0x02,(byte)0x05,0}));
// r.getBytes() == 90 00 <- correct
atr = card.getATR(); // answer to reset
// STEP 3. select file in MF, as in STEP 1
r = channel.transmit(new CommandAPDU(new byte[]{0,(byte)0xA4,(byte)0x02,(byte)0x0C,(byte)0x02,0,(byte)0x02,0}));
// r.getBytes() == 6A 82 <- fail, not found
card.disconnect(false);
我的错误在哪里?或者我怎样才能重置卡?
最佳答案
Card.getATR()
未指定重置卡。它只是返回卡所请求的 ATR。您可能应该使用 disconnect(true)
相反,然后重新连接到卡。
关于java - getATR() 不会重置 javax.smartcardio 中的智能卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17453189/