views:

492

answers:

1

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.

+2  A: 

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?

kgiannakakis