我正在尝试将使用RSA加密的加密算法从Java转换为Python。
我已经做了一周了,并取得了一些进展,但我一直在转换下面这个Java特定的函数。
private static String encryptMessage(String randomToken, PublicKey publicKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return Base64.encodeBase64String(cipher.doFinal(randomToken.getBytes()));
}
我正试图弄清楚如何将Java中这种格式的公钥传递到要传递到函数中的python数据类型中。
{public=Sun RSA public key, 2048 bits
params: null
modulus: 5438....
public exponent:12237}
一旦我能够以正确的格式传递密钥。函数中与python等效的调用是什么?
一些援助和指导将非常有帮助。
使用pycryptodome库,我能够使用模数和指数构造正确的公钥。
https://pycryptodome.readthedocs.io/en/latest/src/public_key/rsa.html#Crypto.PublicKey.RSA.construct