我在 cref 上安装 javacard 小程序时遇到问题。
我从 oracle javacard 示例中举了一个简单的例子 - HelloWorld 并添加了两个额外的行 - import sim.toolkit.*; 和私有 ToolkitRegistry 注册;。这是小程序的代码
package helloworld;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;
import sim.toolkit.*;
public class Hello extends Applet {
private byte[] echoBytes;
private static final short LENGTH_ECHO_BYTES = 256;
private ToolkitRegistry reg;
/**
* Only this class's install method should create the applet object.
*/
protected Hello() {
echoBytes = new byte[LENGTH_ECHO_BYTES];
register();
}
/**
* Installs this applet.
*
* @param bArray
* the array containing installation parameters
* @param bOffset
* the starting offset in bArray
* @param bLength
* the length in bytes of the parameter data in bArray
*/
public static void install(byte[] bArray, short bOffset, byte bLength) {
new Hello();
}
/**
* Processes an incoming APDU.
*
* @see APDU
* @param apdu
* the incoming APDU
* @exception ISOException
* with the response bytes per ISO 7816-4
*/
public void process(APDU apdu) {
byte buffer[] = apdu.getBuffer();
// check SELECT APDU command
if ((buffer[ISO7816.OFFSET_CLA] == 0) &&
(buffer[ISO7816.OFFSET_INS] == (byte) (0xA4))) {
return;
}
short bytesRead = apdu.setIncomingAndReceive();
short echoOffset = (short) 0;
while (bytesRead > 0) {
Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
echoOffset += bytesRead;
bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
}
apdu.setOutgoing();
apdu.setOutgoingLength((short) (echoOffset + 5));
// echo header
apdu.sendBytes((short) 0, (short) 5);
// echo data
apdu.sendBytesLong(echoBytes, (short) 0, echoOffset);
}
}
在添加这些行之前,我的小程序安装在 cref 上没有问题(SW1 SW2 90 00),但在这些编辑之后,我在安装中遇到了问题 - SW1 SW2 0x6438,这意味着找不到导入的包。
我做错了什么?在编译期间,我使用了 sim.toolkit jar 文件,在生成 .cap 文件期间使用了 sim 工具包中的导出文件。