使用 pycrypto (RSA) 签名和验证数据
我试图熟悉 pycrypto 模块,但缺乏清晰的文档使事情变得困难。
首先,我想了解签名和验证数据。有人可以提供一个如何编写的示例吗?
I am trying to familiarize myself with the pycrypto module, but the lack of clear documentation makes things difficult.
To start with, I would like to understand signing and verifying data. Could someone please provide an example for how this would be written?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 示例的充实版本旧的 PyCrypto 文档:
确保您使用的是
pycryptodome
而不是pycrypto
(未维护!)pycryptodome 可以使用
pip install pycryptodome
安装>This is a fleshed-out version of the example in the old PyCrypto documentation:
Ensure you are using
pycryptodome
and notpycrypto
(which is unmaintained!)pycryptodome can be installed with
pip install pycryptodome
下面是我创建的 辅助类,用于执行所有必要的 RSA 功能(加密、解密、签名、验证签名并生成新密钥)
rsa.py
示例用法
Below is the helper class I created to perform all necessary RSA functions (encryption, decryption, signing, verifying signature & generating new keys)
rsa.py
Sample Usage
根据文档:
https: //www.dlitz.net/software/pycrypto/api/current/Crypto.PublicKey.RSA._RSAobj-class.html
你不应该在实际代码中使用 PyCrypto 中的 Crypto.PublicKey.RSA.sign 函数:
我最终使用了实现 PKCS1_v1_5 的 RSA 模块。 签名文档非常简单。其他人建议使用 M2Crypto。
According to the documentation at:
https://www.dlitz.net/software/pycrypto/api/current/Crypto.PublicKey.RSA._RSAobj-class.html
you should not use Crypto.PublicKey.RSA.sign function from PyCrypto in real code:
I ended up using the RSA module that implements PKCS1_v1_5. The documentation for signing was pretty straight forward. Others have recommended use M2Crypto.