我正在研究JavaCard,我在Eclipse上开发了一个带有JCDE的applet:
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时,我有以下错误:
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说
Exception from the invoked install() method:public static void metispackage.SignatureGPS.install(byte[],short,byte) throws javacard.framework.ISOException
有人知道我的安装方法出了什么问题吗?我搜索谷歌但我发现没有解决我的问题:( SW1 = 64 SW2 = 44表示小程序创建失败但我不明白为什么......
答案 0 :(得分:4)
正如您已发现on your own,new BigNumber((short)100);
提出ArithmeticException
。您可以使用try-catch块捕获该异常:
try {
s = new BigNumber((short)100);
} catch (ArithmeticException e) {
// TODO: handle exception
}
但这既不会解决问题的根源,也不会允许您使用BigNumber
对象,因为它们永远不会被创建。
BigNumber
的构造函数引发ArithmeticException
,因为100字节容量超过了JCWDE实现支持的最大容量。 API documentation表示BigNumber
的实现只需要支持至少8个字节。因此,您可能希望测试较小的容量值,以便找出JCWDE实现的最大容量。
答案 1 :(得分:2)
所以,我终于解决了我的问题...... 问题是s = new BigNumber((short)100)抛出异常,所以我不得不这样修改我的代码:
try {
s = new BigNumber((short)100);
x = new BigNumber((short)100);
} catch(ArithmeticException e){
}
现在我可以在没有JCWDE问题的情况下测试我的applet。