简体   繁体   中英

How to use .pem file with Python M2Crypto

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

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.

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?

尝试这个:

RSA.load_key('mykey.pem')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM