2

我正在尝试将小程序安装到 J3A040 JCOP 卡中。

作为安装方法,我有以下内容:

protected MainApplet() {

    try {
        // CREATE RSA KEYS AND PAIR       
        m_keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);
        // STARTS ON-CARD KEY GENERATION PROCESS
        m_keyPair.genKeyPair();
        // OBTAIN KEY REFERENCES
        m_publicKey = (RSAPublicKey) m_keyPair.getPublic();
        m_privateKey = (RSAPrivateKey) m_keyPair.getPrivate();
    } catch (CryptoException c) {
        //this line will give you the reason of problem 
        short reason = c.getReason();
        ISOException.throwIt(reason);       // for check
    }

    register();
}

安装总是失败并出现以下错误:

pro.javacard.gp.GPException: Install for Install and make selectable failed SW: 6A80
        at pro.javacard.gp.GlobalPlatform.check(GlobalPlatform.java:1092)
        at pro.javacard.gp.GlobalPlatform.installAndMakeSelectable(GlobalPlatform.java:798)
        at pro.javacard.gp.GPTool.main(GPTool.java:478)

但是,如果我删除密钥对生成,一切正常。我已阅读卡规格,它代表:

. RSA 和 RSA CRT(1280 到 2048 位密钥)用于加密/解密以及签名生成和验证1 d。在安全环境中生成 RSA CRT 密钥(1280 到 2048 位密钥)

我想应该问题不大。

有什么猜测吗?

4

1 回答 1

3

ALG_RSA_CRT问题是由无效转换引起的:您要求使用中文提醒定理格式 ( )的私钥的 RSA 密钥对。

这就是为什么该getPrivate()方法不返回RsaPrivateKey实例,而是返回RsaPrivateCrtKey实例的原因。强制转换为RsaPrivateKey导致6A80状态字。

因此,您应该使用标准算法:

m_keyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048);

,或使用正确的演员表:

m_publicKey = (RSAPublicKey) m_keyPair.getPublic();
m_privateKey = (RSAPrivateCrtKey) m_keyPair.getPrivate();
于 2015-04-02T13:08:55.900 回答