【问题标题】:Javacard send RSA Public Key in APDUJavacard在APDU中发送RSA公钥
【发布时间】:2017-03-09 08:54:17
【问题描述】:

通过 APDU 发送 JavaCard RSAPublicKey 的最佳解决方案是什么? 获取指数和模块并将它们打包成一个字节数组?

【问题讨论】:

    标签: cryptography rsa javacard apdu


    【解决方案1】:

    是的,您需要将序列化的指数和模数作为字节数组一起发送。这两种方法可以解决您的问题:

    //reads the key object and stores it into the buffer
    private final short serializeKey(RSAPublicKey key, byte[] buffer, short offset) {
        short expLen = key.getExponent(buffer, (short) (offset + 2));
        Util.setShort(buffer, offset, expLen);
        short modLen = key.getModulus(buffer, (short) (offset + 4 + expLen));
        Util.setShort(buffer, offset + 2 + expLen, modLen);
        return (short) (4 + expLen + modLen);
    }
    
    //reads the key from the buffer and stores it inside the key object
    private final short deserializeKey(RSAPublicKey key, byte[] buffer, short offset) {
        short expLen = Util.getShort(buffer, offset);
        key.setExponent(buffer, (short) (offset + 2), expLen);
        short modLen = Util.getShort(buffer, (short) (offset + 2 + expLen));
        key.setModulus(buffer, (short) (offset + 4 + expLen), modLen);
        return (short) (4 + expLen + modLen);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 2014-08-03
      • 2017-02-06
      • 2020-12-19
      • 1970-01-01
      相关资源
      最近更新 更多