Ich verwende Java javax.smartcard-Bibliothek, um Daten von einer Smartcard (SIM-Karte) zu lesen. Aber ich kann meinen Code nicht zur Überprüfung meiner PIN verwenden. Hier ist mein Code:Überprüfung der Smartcard-PIN mit dem APDU-Befehl nicht möglich
public class CopyOfCardReader {
public static final CommandAPDU SELECT_FILE_EEEE = new CommandAPDU(new byte[] { 0x00, (byte) 0xA4, 0x01, 0x0C, 0x02, (byte) 0xEE, (byte) 0xEE });
public static final CommandAPDU SELECT_MASTER_FILE = new CommandAPDU(new byte[] { 0x00, (byte) 0xA4, 0x00, 0x0C });
public static final CommandAPDU DISABLE_PIN = new CommandAPDU(new byte[] { 0x00, (byte) 0x26, 0x00, 0x00 });
public static void main(String[] args) {
try {
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = null;
terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
CardTerminal terminal = terminals.get(0);
Card card = terminal.connect("T=0");
System.out.println("card: " + card);
ATR atr = card.getATR();
System.out.print("ATR: ");
for (byte b : atr.getBytes()) {
System.out.print(b);
}
System.out.println();
CardChannel channel = card.getBasicChannel();
byte[] pin = "1234".getBytes();
byte arg0 = (byte) 0x00;
byte arg1 = (byte) 0x20;
byte arg2 = (byte) 0x00;
byte arg3 = (byte) 0x01;
CommandAPDU command = new CommandAPDU(arg0, arg1, arg2, arg3, pin);
ResponseAPDU request = channel.transmit(command);
System.out.println("answer pin verify request: " + request.toString()); // response
ResponseAPDU rmaster = channel.transmit(SELECT_MASTER_FILE);
System.out.println("answer rmaster file: " + rmaster.toString()); // response
System.out.println();
ResponseAPDU rPinDiable = channel.transmit(new CommandAPDU(new byte[] { (byte) 0x00, (byte) 0x26, 0x00, 0x00 }));
System.out.println("answer DISABLE PIN: " + rPinDiable.toString()); // response
ResponseAPDU rverify2 = channel.transmit(new CommandAPDU(0x00, 0x20, 0x00, 0x01, new byte[] { 0x31, 0x32, 0x33, 0x34, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
System.out.println("answer rverify2 pin2: " + rverify2.toString()); // response
byte[] pin2 = "1234".getBytes();
byte arg02 = (byte) 0x01;
byte arg12 = (byte) 0x26;
byte arg22 = (byte) 0x00;
byte arg32 = (byte) 0x01;
CommandAPDU command2 = new CommandAPDU(arg02, arg12, arg22, arg32, pin2);
ResponseAPDU request2 = channel.transmit(command2);
System.out.println("answer pin disable request: " + request2.toString()); // response
byte[] baReadUID = new byte[5];
baReadUID = new byte[] { (byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
command = new CommandAPDU(baReadUID);
ResponseAPDU r = channel.transmit(new CommandAPDU(new byte[] { 0X00, (byte) 0XA4, 0X00, 0X00, 0X02, 0X3F, 0X00 }));
System.out.println("answer r UID: " + r.toString()); // response
System.out.print("UUID: ");
for (byte b : r.getData()) {
System.out.print(b); // response
}
System.out.println();
card.disconnect(false);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
Und unten ist Programm Ausgabe:
Terminals: [PC/SC terminal Gemalto USB SmartCard Reader 0]
card: PC/SC card in Gemalto USB SmartCard Reader 0, protocol T=0, state OK
ATR: 5959-106064-126-1110036-155151-1120
answer pin verify request: ResponseAPDU: 2 bytes, SW=6708
answer rmaster file: ResponseAPDU: 2 bytes, SW=9000
answer DISABLE PIN: ResponseAPDU: 2 bytes, SW=6708
answer rverify2 pin2: ResponseAPDU: 2 bytes, SW=6a88
answer pin disable request: ResponseAPDU: 2 bytes, SW=6708
answer r UID: ResponseAPDU: 37 bytes, SW=9000
UUID: 9833-126212033-1252630-917-1281113-125236-15-11815-11731585-1-586-11210-12511
Lesestammdatei und UUID ist erfolgreich, aber alle anderen Anweisungen gescheitert sind. Gibt es jemanden, der weiß, was ein Problem mit meinem Code ist? Bitte helfen Sie.
Ihr AID scheint falsch zu sein ... '6A82' bedeutet" Anwendung konnte nicht gefunden werden ". – vojta
Ok, ich habe diesen Befehl für die Anwendung entfernt. Abgesehen davon funktioniert meine PIN-Bestätigung nicht? Warum bekomme ich Fehler 6708 "Länge falsch"? –