JCWDE:install() 方法的异常 [英] JCWDE : Exception from install() method

查看:36
本文介绍了JCWDE:install() 方法的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 JavaCard,我在 Eclipse 上使用 JCDE 开发了一个小程序:

I am working on JavaCard and I developed an applet with JCDE on Eclipse:

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;
import javacardx.framework.math.BigNumber;
import javacard.security.CryptoException;
import javacard.security.MessageDigest;

public class SignatureGPS extends Applet {
    public static final byte CLA = (byte) 0xB0;
    public static final byte INS = (byte) 0x00;

    private BigNumber s;
    private BigNumber x;
    private MessageDigest h;

    private SignatureGPS() {
        s = new BigNumber((short) 100);
        x = new BigNumber((short) 100);
        try {
            h = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false);
        } catch (CryptoException e) {
            if (e.getReason() == CryptoException.NO_SUCH_ALGORITHM){
            }
        }
    }


    public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
        new SignatureGPS().register();
    }


    public void process(APDU apdu) throws ISOException {
        byte[] buffer = apdu.getBuffer();

        if (this.selectingApplet()) return;

        if (buffer[ISO7816.OFFSET_CLA] != CLA)
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        ...
 }

}

但是当我启动 JCWDE 和 APDUTOOL 时,出现以下错误:

But When I launch JCWDE and APDUTOOL, I have the following errors :

Java Card 2.2.2 APDU Tool, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
Opening connection to localhost on port 9025.
Connected.
powerup;
// Select the installer applet
0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
// create SignatureGPS applet
0x80 0xB8 0x00 0x00 0xd 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x01 0x00 0x7F;Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00 
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 90, SW2: 00
// select SignatureGPS applet
0x00 0xA4 0x04 0x00 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x01 0x7F;CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 0d, 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 01, 00, Le: 00, SW1: 64, SW2: 44

在 Eclipse 中,JCWDE 说

And in Eclipse, JCWDE says

 Exception from the invoked install() method:public static void metispackage.SignatureGPS.install(byte[],short,byte) throws javacard.framework.ISOException

有人知道我的 install 方法出了什么问题吗?我在谷歌上搜索,但我没有发现任何可以解决我的问题:( SW1 = 64 SW2 = 44 表示小程序创建失败,但我不知道为什么...

Does anybody know what is going wrong with my install method ? I searched on google but I found nothing to solve my problem :( SW1 = 64 SW2 = 44 indicates that the applet creation failed but I have no idea why...

推荐答案

正如您已经自己发现new BigNumber((short)100); 引发 ArithmeticException.您可以使用 try-catch 块捕获该异常:

As you already found out on your own, new BigNumber((short)100); raises an ArithmeticException. You can catch that exception with a try-catch block:

try {
    s = new BigNumber((short)100);
} catch (ArithmeticException e) {
    // TODO: handle exception
}

但这既不能解决问题的根源,也不能让您使用 BigNumber 对象,因为它们永远不会被创建.

But that will neither solve the source of the problem nor allow you to use the BigNumber objects as they will never be created.

BigNumber 的构造函数引发 ArithmeticException,因为 100 字节容量超过了 JCWDE 实现支持的最大容量.API文档 声明 BigNumber 的实现只需要支持至少 8 个字节.因此,您可能需要测试较小的容量值,以找出 JCWDE 实现的最大容量是多少.

The constructor of BigNumber raises an ArithmeticException because 100 bytes capacity exceeds the supported maximum capacity of the JCWDE implementation. The API documentation states that implementations of BigNumber only need to support at least 8 bytes. Therefore, you may want to test smaller capacity values in order to find out what the maximum capacity of the JCWDE implementation is.

这篇关于JCWDE:install() 方法的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆