从证书中提取公钥并加密数据
这是家庭作业! 我使用 get_peer_certificate()
获取服务器的证书 并调用 dump_certificate 将证书转储到变量中。格式是 PEM,看起来很适合我。
-----BEGIN CERTIFICATE-----
GIBBERISH................
......................
........................
-----END CERTIFICATE-----
如何从此文件('server.pubkey')中提取服务器的公钥并使用 RSA 算法和任何 python 库加密明文。在撰写本文时,我正在使用 pyOpenSSL
This is for a homework assignment!
I get the server's certificate using get_peer_certificate()
and the calling dump_certificate
to dump the certificate in a variable. The format is PEM and looks right to me.
-----BEGIN CERTIFICATE-----
GIBBERISH................
......................
........................
-----END CERTIFICATE-----
How do I extract the server's public key from this file ('server.pubkey') and encrypt plaintext
using RSA
algorithm and any python library. At the time of writing this, I am using pyOpenSSL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议使用更广泛的 加密库,例如 M2Crypto ,它具有 X509 证书功能以及 RSA 加密:
I'd recommend using a more broad crypto library such as M2Crypto which has the X509 certificate functions as well as RSA encryption:
来源:https://pyjwt.readthedocs.io/en/stable/faq.html< /a>
Source: https://pyjwt.readthedocs.io/en/stable/faq.html
请注意,不建议将 OpenSSL 库 用于这些目的。相反,密码学库被指出。它得到维护并定期更新。
假设您有 Pem 格式的证书,以下代码块将为您提供字符串形式的公钥。
Note that OpenSSL library is not recommended to be used for those purposes. Instead, cryptography library is pointed. It is maintained and regularly updated.
Assuming you have the certificate in Pem format, the following code block will give you public key in string.