如何在Python M2Crypto中使用.pem文件 [英] How to use .pem file with Python M2Crypto
本文介绍了如何在Python M2Crypto中使用.pem文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用openssl生成RSA密钥对:
To generate an RSA key pair I used openssl:
openssl genrsa -out my_key.private.pem 1024
openssl rsa -in my_key.private.pem -pubout -out my_key.public.pem
现在,我想在另一个.py文件的功能中使用此my_key.public.pem文件:
Now I want to use this my_key.public.pem file in a function of another .py file:
import M2Crypto
from M2Crypto import RSA,SSL
def encrypt():
pk = open( 'my_key.public.pem', 'rb' ).read()
rsa = M2Crypto.RSA.load_pub_key(pk)
print rsa;
我做对了吗? 这两个文件都在同一目录中,但是此功能未提供任何输出.
Am I doing it right? Both files are in same directory, but this function is not giving any output.
推荐答案
根据文档 load_pub_key
需要一个文件名作为输入.它返回一个M2Crypto.RSA.RSA_pub
对象,该对象对打印没有任何意义.到底想达到什么目的?
According to the documentation the load_pub_key
expects a file name as input. It returns a M2Crypto.RSA.RSA_pub
object, which doesn't make sense to print. What exactly are trying to achieve?
这篇关于如何在Python M2Crypto中使用.pem文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文