getATR()不会重置javax.smartcardio中的智能卡

时间:2013-07-03 16:20:00

标签: java smartcard apdu

我正在使用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);

我的错误在哪里?或者我如何重置卡?

1 个答案:

答案 0 :(得分:2)

Card.getATR()未指定重置卡。它只返回卡中请求的ATR。您应该使用disconnect(true)代替,然后重新连接到卡。​​