首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java卡APDU错误

Java卡APDU错误
EN

Stack Overflow用户
提问于 2016-04-09 00:30:55
回答 1查看 1.1K关注 0票数 2

我试图将一个简单的APDU发送到Java (我附上了下面applet的简单代码),.I已经在Eclipse模拟器中测试了applet,但是当我想向applet发送APDU时,它失败了:send_APDU() returns 0x80206E00 (6E00: Wrong CLA byte.) .Applet已经安装到卡中(我使用了GpShell来完成),.Here是我用来发送APDU的脚本的完整输出。

代码语言:javascript
复制
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的完整代码。

代码语言:javascript
复制
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;
    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-09 03:44:57

为了与applet进行通信,必须先选择applet。

要做到这一点,你有两个选择。第一个选项是在applet安装阶段选择applet默认选项,并在每次启动后使其隐式地选择applet。第二个选项是在发送其他命令之前发送与applet连接的SELECT APDU命令。

选择APDU命令= 00A40400 <AID Length> <AID>

另外,响应命令的实体不是applet,很可能是默认选择的applet,即卡管理器。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36511386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档