python function for retrieving key and encryption

jayshree jayshree06comp at gmail.com
Thu Jul 23 02:37:17 EDT 2009


On Jul 21, 8:59 pm, Piet van Oostrum <p... at cs.uu.nl> wrote:
> >>>>> jayshree <jayshree06c... at gmail.com> (j) wrote:
> >j> M2Crypto package not showing the 'recipient_public_key.pem' file at
> >j> linux terminal .how do i get/connect with recipient public key.
> >j> exactly i need to check how can i open this file through linux
> >j> commands.
> >j> import M2Crypto def encrypt(): recip = M2Crypto.RSA.load_pub_key(open
> >j> ('recipient_public_key.pem','rb').read()) print recip; plaintext =
> >j> whatever i need to encrypt msg = recip.public_encrypt
> >j> (plaintext,RSA.pkcs1_padding) print msg;
> >j> after calling the function its not giving any output and even any
> >j> error
> >j> i also tried as 'Will' said
> >j> pk = open('public_key.pem','rb').read() print pk; rsa =
> >j> M2Crypto.RSA.load_pub_key(pk)
> >j> whats the mistake i am not getting .will somebody help me out.
> >j> is something wrong in opening 'recipient_public_key.pem'. is M2Crypto
> >j> contain this file inbuilt .from where this file taking public key of
> >j> the recipient i'. what this file contain and how it will work .should
> >j> i need to create such a file for my purpose.if it is then how can i
> >j> create this  and how it will retrieve the key,where i recognize my
> >j> recipient to get his public key .is something like database at server.
> >j> please give me a quick response......
> >j> looking for your answer.
>
> Please:
> 1. Type your python code with newlines and proper indentation.
> 2. Show the error messages that your code gives when you run it.
> 3. Use proper capital letters at the beginning of your sentences.
> 4. Don't fire so many questions in rapid succession.
>
> 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.
> --
> Piet van Oostrum <p... at cs.uu.nl>
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p... at vanoostrum.org- Hide quoted text -
>
> - Show quoted text -
Here is the code that i used

import M2Crypto
from M2Crypto import RSA

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


    encrypt()


error coming like - IOError: [Errno 2] No such file or directory:
'recipient_public_key.pem'

Is this not the inbuilt file.
How should i create such type of file.



More information about the Python-list mailing list