可以使用openssl命令来实现Python RSA和Base64算法的等效功能吗?
例如,已知RSA公钥和要加密的密码。 Python算法是
ciphertext = base64.b64encode(PKCS1_v1_5.new(pubkey).encrypt(password.encode('utf-8')))
假设密码为123456,公钥为pubkey.pem。以下openssl命令是否等效于Python算法?
echo 123456 | openssl rsautl -encrypt -pubin -inkey pubkey.pem -out ciphertext.txt | openssl enc -e -base64 -in ciphertext.txt -out r.txt
r.txt的结果等于Python算法的密文吗?
答案 0 :(得分:0)
是的,当且仅当您的密码为“ 123456”时,才应该如此。
当然,PKCS#1 v1.5填充执行的随机化意味着密文总是不同的。
要测试:在Python中使用相反的操作和私钥解密密文。为了更加确定,也可以使用openssl
进行解密。