我正在使用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);
我的错误在哪里?或者我怎样才能重置卡?