ajay
ajay

Reputation:

python function for retrieving key and encryption

M2Crypto package is not showing the 'recipient_public_key.pem' file at linux terminal.

How do I get/connect with recipient public key.

Exactly, I need to check how can I open this file through linux commands.

import M2Crypto
def encrypt():
    recip = M2Crypto.RSA.load_pub_key(open('recipient_public_key.pem','rb').read())
    print recip;
    plaintext = whatever i need to encrypt
    msg = recip.public_encrypt(plaintext,RSA.pkcs1_padding)
    print msg;

after calling the function its not giving any output and even any error

i also tried as 'Will' said

pk = open('public_key.pem','rb').read()
print pk;
rsa = M2Crypto.RSA.load_pub_key(pk)

what is the mistake I am not getting?

Upvotes: 0

Views: 207

Answers (1)

balpha
balpha

Reputation: 50898

I have never used M2Crypto, but according to the API documentation, load_pub_key expects the file name as the argument, not the key itself. Try

recip = M2Crypto.RSA.load_pub_key('recipient_public_key.pem')

Upvotes: 1

Related Questions