繁体   English   中英

在 cref 上导入 javacard 小程序

[英]Import javacard applet on cref

我有一个与在 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 工具包的导出文件。

据我所知,与 Java Card Development Kit 捆绑的模拟器不支持 SIM Toolkit 功能。

您可能想要使用例如Gemalto Developer Suite

祝你好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM