在load_pub_key中访问文件 [英] File accessing in load_pub_key

查看:166
本文介绍了在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方法中,以便只需传递文件名即可访问它?

How do I pass the file into load_pub_key method so it can be accessible by simply passing the file name?

推荐答案

我也有同样的问题.我尝试加载文件处理程序而不是路径,但没有帮助.

I also have the same issue. I tried loading a file handler instead of path but it didn't help.

锻炼的事情是使用M2Crypto的X509模块.您可以尝试使用以下功能来获取公钥实例:

The thing that workout was using X509 module from M2Crypto. You can try use this functions to obtain a public key instance:

certificate = M2Crypto.X509.load_cert(cert_path)
pubkey = certificate.get_pubkey()

更多详细信息,请参见以下答案: 使用m2crypto的RSACryptoServiceProvider消息签名验证

More details in the following answer: RSACryptoServiceProvider message signature verification with m2crypto

这篇关于在load_pub_key中访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆