[英]How to use .pem file with Python M2Crypto
To generate an RSA key pair I used openssl: 要生成RSA密钥对,我使用了openssl:
openssl genrsa -out my_key.private.pem 1024
openssl rsa -in my_key.private.pem -pubout -out my_key.public.pem
Now I want to use this my_key.public.pem file in a function of another .py file: 现在,我想在另一个.py文件的功能中使用此my_key.public.pem文件:
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. 这两个文件都在同一目录中,但是此功能未提供任何输出。
According to the documentation the load_pub_key
expects a file name as input. 根据文档 , load_pub_key
需要文件名作为输入。 It returns a M2Crypto.RSA.RSA_pub
object, which doesn't make sense to print. 它返回一个M2Crypto.RSA.RSA_pub
对象,这对打印没有意义。 What exactly are trying to achieve? 到底想达到什么目的?
尝试这个:
RSA.load_key('mykey.pem')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.