【问题标题】:Can use openssl instead of Python RSA and Base64 algorithms?可以使用 openssl 代替 Python RSA 和 Base64 算法吗?
【发布时间】:2019-10-13 04:38:22
【问题描述】:

可以使用 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算法的密文?

【问题讨论】:

  • 欢迎来到 crypto.stackexchange - 这似乎是一个编程问题,编程问题在这里是题外话,即使它们是关于密码学的。编程问题的正确家是stackoverflow;我可以帮你迁移到那里。

标签: python encryption openssl rsa pkcs#1


【解决方案1】:

是的,当然,当且仅当您的密码是“123456”时,它应该是。

当然,PKCS#1 v1.5 填充执行的随机化意味着密文总是不同的。

测试:在 Python 中使用反向操作和私钥解密密文。为了更加确定,也可以使用openssl 解密。

【讨论】:

  • 您使用echo -n(在支持它的版本上)来避免添加虚假的换行符。 (并且不要使用 Windows CMD,echo foo | something 实际上会回显 f o o SP CR LF。)
  • 谢谢提醒,是Windows CMD导致的问题。当用-in替换echo时,问题就解决了。再次感谢您!
猜你喜欢
  • 1970-01-01
  • 2021-11-16
  • 1970-01-01
  • 2016-04-05
  • 2015-05-09
  • 2019-08-10
  • 2012-06-14
  • 1970-01-01
  • 2011-12-11
相关资源
最近更新 更多