【发布时间】:2017-04-12 07:58:31
【问题描述】:
我有一个 128 字节的 RSA 密钥。我在 javacard 小程序中使用公钥加密了长度为 128 字节的数据,并在 C 应用程序中使用相同密钥对的私钥对其进行了解密。结果数据与原始数据不同。原因是什么?
Javacard 代码
asymCipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
asymCipher.init(PkTCA, Cipher.MODE_ENCRYPT);
asymCipher.doFinal(data, (short)0, (short)data.length, encrypted, (short)0);
C 代码
int padding = RSA_NO_PADDING;
int private_decrypt(unsigned char * enc_data,int data_len,unsigned char * key, unsigned char *decrypted)
{
RSA * rsa = createRSA(key,0);
int result = RSA_private_decrypt(data_len,enc_data,decrypted,rsa,padding);
return result;
}
encrypted_length = private_decrypt(PkAIKR,strlen(PkAIKR),privateKeyTCA,PkAIKR_dec);
【问题讨论】:
-
给我们您的 RSA 密钥和所有数据。
标签: c encryption openssl javacard