Ich versuche eine einfache APDU an eine Java Card zu senden (ich habe den einfachen Code des Applet unten angefügt). Ich habe das Applet bereits im Eclipse Simulator getestet, aber wenn ich eine APDU an die Applet schlägt mit dem folgenden Fehler fehl: send_APDU() returns 0x80206E00 (6E00: Wrong CLA byte.)
. Applet ist bereits in der Karte installiert (ich habe GpShell dazu verwendet). Hier ist die volle Ausgabe von dem Skript, das ich verwendet habe, um die APDU zu senden.Java Card APDU Fehler
D:\GPShell-1.4.4>GPShell.exe send_APDU.txt
establish_context
enable_trace
enable_timer
card_connect
command time: 15 ms
send_apdu -sc 0 -APDU b0000000010000
Command --> B0000000010000
Wrapped command --> B0000000010000
Response <-- 6E00
send_APDU() returns 0x80206E00 (6E00: Wrong CLA byte.)
command time: 860 ms
card_disconnect
command time: 31 ms
release_context
command time: 0 ms
Hier ist der vollständige Code des Applets.
public class Contor extends Applet {
private byte contor = 0;
private final static byte CLS=(byte)0xB0;
private final static byte INC=(byte)0x00;
private final static byte DEC=(byte)0x01;
private final static byte GET=(byte)0x02;
private final static byte INIT=(byte)0x03;
private Contor() {
}
public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
new Contor().register();
}
public void process(APDU apdu) throws ISOException {
if(this.selectingApplet())return;
byte[] buffer = apdu.getBuffer();
if(buffer[ISO7816.OFFSET_CLA] != CLS)
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
switch(buffer[ISO7816.OFFSET_INS])
{
case INC:contor++; break;
case DEC:contor--; break;
case GET:
buffer[0] = contor;
apdu.setOutgoingAndSend((short)0,(short)1);
break;
case INIT:
apdu.setIncomingAndReceive();
contor = buffer[ISO7816.OFFSET_CDATA];
break;
}
}
In Bezug auf Ihren zweiten Punkt: Da beide 'Puffer [ISO7816.OFFSET_CLA]' und 'CLS' als Byte deklariert sind, enthalten beide den gleichen vorzeichenbehafteten Wert (dh -80 für' (Byte) 0xB0') und der Vergleich wird perfekt funktionieren. Das Umwandeln nach short/int, das Abschneiden und Rückübersetzen auf Byte ändert nichts und ist in diesem Fall völlig nutzlos. –
@MichaelRoland Sie haben völlig Recht. Vielen Dank. Antwort aktualisiert Casting und Bit-weise und ist in Fällen erforderlich, in denen wir Pufferelemente mit einem kurzen/int Wert größer als "127" vergleichen. Recht? – Abraham