我嘗試從奧地利電子卡片上讀取信息以獲取名字和姓氏。如何將來自奧地利電子卡的ResponseAPDU解碼爲XML?
現在有效的是:訪問該卡,發送APDU命令並獲取字節數組的信息。
如何將接收到的字節數組轉換爲XML以提取所需的數據?
下面是代碼:
import java.util.List;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import javax.smartcardio.TerminalFactory;
public class Main2 {
public static void main(String[] args) {
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals;
try {
terminals = factory.terminals().list();
CardTerminal terminal = terminals.get(0);
Card card = terminal.connect("*");
CardChannel channel = card.getBasicChannel();
// Select the MF
byte[] aid = { (byte) 0xD0, 0x40, 0x00, 0x00, 0x17, 0x01, 0x01, 0x01 };
ResponseAPDU resp = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04, 0x00, aid));
System.out.println("Response: " + resp.toString());
// Select the Personaladata-file
byte[] aid2 = { (byte) 0xEF, 0x01 };
resp = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x02, 0x04, aid2));
System.out.println("Response: " + resp.toString());
// Get the data from the file
resp = channel.transmit(new CommandAPDU(0x00, 0xB0, 0x00, 0x00, 0xFF));
System.out.println("Response: " + resp.toString());
System.out.println("Response String: " + new String(resp.getData()));
card.disconnect(false);
} catch (CardException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
要知道,給定名稱的索引,姓和性別領域可能會有所不同,所以'asn1.getObjectAt (2)''不會總是給你指定的名字等等。例如,這是一個前綴的學術名稱或後綴學術學位的附加字段的情況。我只是檢查了我以前的卡片,如果沒有標題或後綴,這些字段根本不存在。 –