Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cryptography Javacard在APDU中发送RSA公钥_Cryptography_Rsa_Javacard_Apdu - Fatal编程技术网

Cryptography Javacard在APDU中发送RSA公钥

Cryptography Javacard在APDU中发送RSA公钥,cryptography,rsa,javacard,apdu,Cryptography,Rsa,Javacard,Apdu,通过APDU发送JavaCard公钥的好解决方案是什么? 获取指数和模块并将它们打包到字节数组中?是的,您需要将指数和模块作为字节数组一起序列化发送。这两种方法可以解决您的问题: //reads the key object and stores it into the buffer private final short serializeKey(RSAPublicKey key, byte[] buffer, short offset) { short expLen = key.ge

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

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

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