python function for retrieving key and encryption

jayshree jayshree06comp at
Mon Jul 27 08:47:00 CEST 2009

On Jul 23, 5:48 pm, Piet van Oostrum <p... at> wrote:
> >>>>> jayshree <jayshree06c... at> (j) wrote:
> >j> On Jul 21, 8:59 pm, Piet van Oostrum <p... at> wrote:
> >>> The recipient_public_key.pem file is the public key of the recipient
> >>> which means the person that is going to receive the encrypted message.
> >>> You should get it from the recipient him/herself or from some key store
> >>> where s/he has deposited it.
> [...]
> >j> error coming like - IOError: [Errno 2] No such file or directory:
> >j> 'recipient_public_key.pem'
> >j> Is this not the inbuilt file.
> >j> How should i create such type of file.
> You don't create it. See above. If you understand what is is you know
> why it can't be builtin. If you don't understand it is better if you
> first learn about OpenSSL, otherwise you run the risk to make serious
> errors.
> If you are just experimenting to create a message for yourself then you
> have to create the public key because you are then the recipient
> yourself. That has been answered on
> --
> Piet van Oostrum <p... at>
> URL:[PGP 8DAE142BE17999C4]
> Private email: p... at

import M2Crypto
from M2Crypto import RSA,SSL
def encrypt():
    pk = open('my_key.public.pem', 'rb').read()
    rsa = M2Crypto.RSA.load_pub_key(pk) #return a M2Crypto.RSA.RSA_pub
    plaintext = 4545479545655576767767686688782344
    msg = rsa.public_encrypt(plaintext,RSA.pkcs1_padding)
    print msg;

This is code i am refering.
The Problem is coming with .pem file.
I also asked this questions at
which has not been answered .
please help me out....


More information about the Python-list mailing list