load_pub_key 中的文件访问
考虑以下代码:
fileHandle = open ( 'test8.pem','w' )
fileHandle.write (data)
pub_key = M2Crypto.RSA.load_pub_key(open('test8.pem'))
这会产生以下错误:
File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 343, in load_pub_key
bio = BIO.openfile(file)
File "/usr/lib/python2.4/site-packages/M2Crypto/BIO.py", line 186, in openfile
return File(open(filename, mode))
IOError: [Errno 2] No such file or directory: ''
如何将文件传递到 load_pub_key
方法中,以便只需传递文件名即可访问它?
Consider the following code:
fileHandle = open ( 'test8.pem','w' )
fileHandle.write (data)
pub_key = M2Crypto.RSA.load_pub_key(open('test8.pem'))
Which produces the following error:
File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 343, in load_pub_key
bio = BIO.openfile(file)
File "/usr/lib/python2.4/site-packages/M2Crypto/BIO.py", line 186, in openfile
return File(open(filename, mode))
IOError: [Errno 2] No such file or directory: ''
How do I pass the file into load_pub_key
method so it can be accessible by simply passing the file name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您传递不带引号的 test8.pem,Python 会将其解释为未定义的变量名称,因此会出现错误。
我不知道您正在使用的具体库,但我猜您需要传递 fileHandle 。
If you pass test8.pem without quotes, Python interprets it as the name of a variable, which is not defined, hence the error.
I don't know the specific library you are using but I would guess that you need to pass fileHandle instead.
这应该适合你:
this should work for you:
我也有同样的问题。我尝试加载文件处理程序而不是路径,但没有帮助。
锻炼的是使用 M2Crypto 的 X509 模块。您可以尝试使用此函数来获取公钥实例:
更多详细信息请参阅以下答案:
使用 m2crypto 验证 RSACryptoServiceProvider 消息签名
I also have the same issue. I tried loading a file handler instead of path but it didn't help.
The thing that workout was using X509 module from M2Crypto. You can try use this functions to obtain a public key instance:
More details in the following answer:
RSACryptoServiceProvider message signature verification with m2crypto