如何使用Python OpenSSL公共密钥对字符串进行加密?
我当前生成OpenSSL公私密钥对的代码:
import OpenSSL
key = OpenSSL.crypto.PKey()
key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048)
public_key = OpenSSL.crypto.dump_publickey(OpenSSL.crypto.FILETYPE_PEM, key)
private_key = OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key)
print(public_key, private_key, sep="\n")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该文档建议您调用要获取一个加密密钥,然后使用Pyca/加密进行加密。
https://www.pypyopenssl.org.org/en/en/stable/stable/pable/api/api/api/crypto。 html
鉴于您的加密密钥:
我应该补充,RSA是主要供签名和验证以及密钥交换的主要。对于一般加密来说太慢了。
The documentation recommends that you call key.to_cryptography_key() to get a cryptographic key, and then use pyca/cryptography to perform the encryption.
https://www.pyopenssl.org/en/stable/api/crypto.html
Given your crypto key:
I should add, RSA is primary intended for signatures and verification, and key exchange. It's way too slow for general encryption.