cryptography - Javacard 在 APDU 中发送 RSA 公钥

标签 cryptography rsa javacard apdu

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

最佳答案

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

//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);
}

关于cryptography - Javacard 在 APDU 中发送 RSA 公钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42690733/

相关文章:

java - 使用什么模式在 Java 中解密来自 iPhone 的 RSA 消息?

java - Java Card 上的椭圆曲线 - 是否可以在 Java Card 上使用外部库?

smartcard - JCOP 2.4.2 Java 卡上的 ECDSA 算法

java - Android Cipher.getInstance() 安全问题

c++ - 使用 AES 解密时前 16 个字节损坏

ssl - 是否使用 rsa :2048 use an SHA-2 cryptographic hash algorithm? 创建的 SSL 证书

javax.crypto.BadPaddingException : Decryption error when using Java RSA encryption

smartcard - 如何更改 javacard 上小程序的生命周期?

linux - Linux 中的字符串加密

hash - 用户密码的 Golang Base64 编码 SHA256 摘要