我试图将一个简单的APDU发送到Java (我附上了下面applet的简单代码),.I已经在Eclipse模拟器中测试了applet,但是当我想向applet发送APDU时,它失败了:send_APDU() returns 0x80206E00 (6E00: Wrong CLA byte.) .Applet已经安装到卡中(我使用了GpShell来完成),.Here是我用来发送APDU的脚本的完整输出。
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这是applet的完整代码。
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;
}
}发布于 2016-04-09 03:44:57
为了与applet进行通信,必须先选择applet。
要做到这一点,你有两个选择。第一个选项是在applet安装阶段选择applet默认选项,并在每次启动后使其隐式地选择applet。第二个选项是在发送其他命令之前发送与applet连接的SELECT APDU命令。
选择APDU命令= 00A40400 <AID Length> <AID>
另外,响应命令的实体不是applet,很可能是默认选择的applet,即卡管理器。
https://stackoverflow.com/questions/36511386
复制相似问题