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