python+encryption
I have the key pair generated by the GPG. Now I want to use the public key for encrypting the password. I need to make a function in Python. Can somebody guide me on how to do this … to encrypt password by the public key ..how can i do this ,which library is best and easy to prefer.i have to work on ssh secure shell client. thanks -- http://mail.python.org/mailman/listinfo/python-list
python function for retrieving key and encryption
M2Crypto package 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) whats the mistake i am not getting .will somebody help me out. is something wrong in opening 'recipient_public_key.pem'. is M2Crypto contain this file inbuilt .from where this file taking public key of the recipient i'. what this file contain and how it will work .should i need to create such a file for my purpose.if it is then how can i create this and how it will retrieve the key,where i recognize my recipient to get his public key .is something like database at server. please give me a quick response.. looking for your answer. -- http://mail.python.org/mailman/listinfo/python-list
Re: python function for retrieving key and encryption
On Jul 21, 8:59 pm, Piet van Oostrum wrote: > >>>>> jayshree (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 > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p...@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. -- http://mail.python.org/mailman/listinfo/python-list
Re: python function for retrieving key and encryption
On Jul 23, 5:48 pm, Piet van Oostrum wrote: > >>>>> jayshree (j) wrote: > >j> On Jul 21, 8:59 pm, Piet van Oostrum 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 > onhttp://stackoverflow.com/questions/1169798/m2crypto-package > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p...@vanoostrum.org 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 object. plaintext = 4545479545655576767767686688782344 msg = rsa.public_encrypt(plaintext,RSA.pkcs1_padding) print msg; encrypt() This is code i am refering. The Problem is coming with .pem file. I also asked this questions at http://stackoverflow.com/questions/1176864/problem-with-the-pem-file-closed which has not been answered . please help me out thanks -- http://mail.python.org/mailman/listinfo/python-list
open a file in python
pk = open('/home/jayshree/my_key.public.pem' , 'rb').read() Please tell me how to open a file placed in any directory or in same directory. After opening this file i want to use the contain (public key ) for encryption thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: open a file in python
On Jul 27, 1:09 pm, Kushal Kumaran wrote: > On Mon, Jul 27, 2009 at 12:58 PM, jayshree wrote: > > pk = open('/home/jayshree/my_key.public.pem' , 'rb').read() > > > Please tell me how to open a file placed in any directory or in same > > directory. > > > After opening this file i want to use the contain (public key ) for > > encryption > > Does the code you've put into your message not read that file? If you > get an exception, copy-paste in the traceback message you get into > your mail. > > -- > kushal try: pk = open('/home/jayshree/my_key.public.pem' , 'rb').read() except IOError: print "Error: can\'t find file or read data" else: print "reading from file successfully" >Still no error it gives .what to do? -- http://mail.python.org/mailman/listinfo/python-list
Re: open a file in python
On Jul 27, 2:55 pm, "Diez B. Roggisch" wrote: > jayshree wrote: > > On Jul 27, 1:09 pm, Kushal Kumaran > > wrote: > >> On Mon, Jul 27, 2009 at 12:58 PM, jayshree > >> wrote: > >> > pk = open('/home/jayshree/my_key.public.pem' , 'rb').read() > > >> > Please tell me how to open a file placed in any directory or in same > >> > directory. > > >> > After opening this file i want to use the contain (public key ) for > >> > encryption > > >> Does the code you've put into your message not read that file? If you > >> get an exception, copy-paste in the traceback message you get into > >> your mail. > > >> -- > >> kushal > > > try: > > pk = open('/home/jayshree/my_key.public.pem' , 'rb').read() > > except IOError: > > print "Error: can\'t find file or read data" > > else: > > print "reading from file successfully" > > >>Still no error it gives .what to do? > > Erm - so it doesn't give an error - which means you have successfully opened > a file, and read it's contents. > > So what exactly is your problem? > > Diez- Hide quoted text - > > - Show quoted text - > The Exact Problem is how to use the key containing by .pem file for > 'encryption' . >can i print the contents of the .pem file see http://stackoverflow.com/questions/1176864/problem-with-the-pem-file -- http://mail.python.org/mailman/listinfo/python-list
problem in encryption
hello , The community members, Using following code : fileHandle = open ('jay1key.py','wb') #fileHandle = open ('jay1key.pem',rb).read() print fileHandle.write (data) #data variable is contains the key fileHandle.close() otp = 'jyshri69' pub_key = M2Crypto.RSA.load_pub_key('jay1key.py') encrypted = pub_key.public_encrypt(otp, M2Crypto.RSA.pkcs1_padding) print "encrypted text is = " print "---" print encrypted the above code gives me following error : None Traceback (most recent call last): File "RetEnc.py", line 71, in ? pub_key = M2Crypto.RSA.load_pub_key('jay1key.py') File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 344, in load_pub_key return load_pub_key_bio(bio) File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 360, in load_pub_key_bio rsa_error() File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 240, in rsa_error raise RSAError, m2.err_reason_error_string(m2.err_get_error()) M2Crypto.RSA.RSAError: no start line not getting how to resolve it ? -- http://mail.python.org/mailman/listinfo/python-list
Re: problem in encryption
On Sep 22, 1:44 pm, jayshree wrote: > hello , > The community members, > > Using following code : > > fileHandle = open ('jay1key.py','wb') > #fileHandle = open ('jay1key.pem',rb).read() > print fileHandle.write (data) #data variable is contains the key > fileHandle.close() > > otp = 'jyshri69' > > pub_key = M2Crypto.RSA.load_pub_key('jay1key.py') > > encrypted = pub_key.public_encrypt(otp, M2Crypto.RSA.pkcs1_padding) > print "encrypted text is = " > print "---" > print encrypted > > the above code gives me following error : > None > Traceback (most recent call last): > File "RetEnc.py", line 71, in ? > pub_key = M2Crypto.RSA.load_pub_key('jay1key.py') > File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 344, > in load_pub_key > return load_pub_key_bio(bio) > File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 360, > in load_pub_key_bio > rsa_error() > File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 240, > in rsa_error > raise RSAError, m2.err_reason_error_string(m2.err_get_error()) > M2Crypto.RSA.RSAError: no start line > > not getting how to resolve it ? the key looks like this : -BEGIN RSA PUBLIC KEY- mQGiBEpz7VIRBADAt9YpYfYHJeGA6d +G261FHW1uA0YXltCWa7TL6JnIsuxvh9vImUoyMJd6 1xEW4TuROTxGcMMiDemQq6HfV9tLi7ptVBLf/8nUEFoGhxS +DPJsy46WmlscKHRIEdIkTYhp uAIMim0q5HWymEqqAfBLwJTOY9sR+nelh0NKepcCqwCgvenJ2R5UgmAh +sOhIBrh3OahZEED /2sRGHi4xRWKePFpttXfb2hry2/jURPae/wYfuI6Xw3k5EO593veGS7Zyjnt+7mVY1N5V/ ey rfXaS3R6GsByG/eRVzRJGU2DSQvmF+q2NC6v2s4KSzr5CVKpn586SGUSg/ aKvXY3EIrpvAGP rHum1wt6P9m9kr/4X8SdVhj7Jti6A/0TA8C2KYhOn/ hSYAMTmhisHan3g2Cm6yNzKeTiq6/0 ooG/ ffcY81zC6+Kw236VGy2bLrMLkboXPuecvaRfz14gJA9SGyInIGQcd78BrX8KZDUpF1Ek KxQqL97YRMQevYV89uQADKT1rDBJPNZ+o9f59WT04tClphk/ quvMMuSVILQaamF5c2ggPGph eXNocmVlQGdtYWlsLmNvbT6IZgQTEQIAJgUCSnPtUgIbAwUJAAFRgAYLCQgHAwIEFQIIAwQW AgMBAh4BAheAAAoJEFjpOQ2vjFvzS0wAn3vf1A8npIY/DMIFFw0/ eGf0FNekAKCBJnub9GVu 9OUY0nISQf7uZZVyI7kBDQRKc+1SEAQAm7Pink6S5+kfHeUoJVldb +VAlHdf7BdvKjVeiKAb dFUa6vR9az+wn8V5asNy/ npEAYnHG2nVFpR8DTlN0eO35p78qXkuWkkpNocLIB3bFwkOCbff P3yaCZp27Vq+9182bAR2Ah10T1KShjWTS/ wfRpSVECYUGUMSh4bJTnbDA2MAAwUEAIcRhF9N OxAsOezkiZBm+tG4BgT0+uWchY7fItJdEqrdrROuCFqWkJLY2uTbhtZ5RMceFAW3s +IYDHLL PwM1O+ZojhvAkGwLyC4F +6RCE62mscvDJQsdwS4L25CaG2Aw97HhY7+bG00TWqGLb9JibKie X1Lk+W8Sde/4UK3Q8tpbiE8EGBECAA8FAkpz7VICGwwFCQABUYAACgkQWOk5Da+MW/ MAAgCg tfUKLOsrFjmyFu7biv7ZwVfejaMAn1QXEJw6hpvte60WZrL0CpS60A6Q -END RSA PUBLIC KEY- -- http://mail.python.org/mailman/listinfo/python-list