使用 OpenSSL 生成的密钥进行 Python RSA 解密
有谁知道使用 Python 库导入 OpenSSL RSA 私钥/公钥(使用密码)并使用它来解密消息的最简单方法。
我查看了 ezPyCrypto,但似乎无法让它识别 OpenSSL RSA 密钥,我尝试使用 importKey 导入密钥,如下所示:
key.importKey(myKey, passphrase='PASSPHRASE')
在我的例子中,myKey 是一个 OpenSSL RSA 公钥/私钥对,表示为一个字符串。
这阻碍了:
必须首先以密钥实例调用未绑定方法 importKey() 参数(改为 str 实例)
API 文档说:
importKey(self, keystring, **kwds)
有人可以建议我如何在使用 ezPyCrypto 时读取密钥吗? 我也尝试过:
key(key, passphrase='PASSPHRASE')
但这会阻碍:
ezPyCrypto.CryptoKeyError:已尝试 导入无效密钥或密码 不好
文档链接:
http://www.freenet.org.nz /ezPyCrypto/detail/index.html
编辑: 只是对此的更新。 已成功导入 RSA 密钥,但解密时遇到实际问题,因为 eqPyCrypto 不支持 AES 块密码。 只是为了让人们知道。 我成功地使用 ncrypt (http://tachyon.in/ncrypt/) 完成了我想做的事情。 由于 SWIG 和 OpenSSL 编译问题,我在 M2Crypto 方面遇到了一些编译问题,尽管安装的版本超出了最低要求。 目前看来,Python 加密/解密框架有点像雷区。 呵呵,谢谢你的帮助。
Does anyone know the simplest way to import an OpenSSL RSA private/public key (using a passphrase) with a Python library and use it to decrypt a message.
I've taken a look at ezPyCrypto, but can't seem to get it to recognise an OpenSSL RSA key, I've tried importing a key with importKey as follows:
key.importKey(myKey, passphrase='PASSPHRASE')
myKey in my case is an OpenSSL RSA public/private keypair represented as a string.
This balks with:
unbound method importKey() must be called with key instance as first
argument (got str instance instead)
The API doc says:
importKey(self, keystring, **kwds)
Can somebody suggest how I read a key in using ezPyCrypto? I've also tried:
key(key, passphrase='PASSPHRASE')
but this balks with:
ezPyCrypto.CryptoKeyError: Attempted
to import invalid key, or passphrase
is bad
Link to docs here:
http://www.freenet.org.nz/ezPyCrypto/detail/index.html
EDIT: Just an update on this. Successfully imported an RSA key, but had real problem decrypting because eqPyCrypto doesn't support the AES block cipher. Just so that people know. I successfully managed to do what I wanted using ncrypt (http://tachyon.in/ncrypt/). I had some compilation issues with M2Crypto because of SWIG and OpenSSL compilation problems, despite having versions installed that exceeded the minimum requirements. It would seem that the Python encryption/decryption frameworks are a bit of a minefield at the moment. Ho hum, thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个错误告诉您需要在
key
的实例上调用importKey
。但是,文档似乎表明这是执行您想要的操作的更好方法:
The first error is telling you that
importKey
needs to be called on an instance ofkey
.However, the documentation seems to suggest that this is a better way of doing what you want:
目前尚不清楚您想要实现什么目标,但您可以尝试一下 M2Crypto。 从我的角度来看,它是可用于 Python 的最佳 OpenSSL 包装器。
以下是 RSA 加密/解密代码示例:
It is not clear what are you trying to achieve, but you could give M2Crypto a try. From my point of view it is the best OpenSSL wrapper available for Python.
Here is a sample RSA encryption/decription code: