problem in encryption

J

jayshree

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 ?
 
J

jayshree

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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vDJQsdwS4L25CaG2Aw97HhY7+bG00TWqGLb9JibKie
X1Lk+W8Sde/4UK3Q8tpbiE8EGBECAA8FAkpz7VICGwwFCQABUYAACgkQWOk5Da+MW/
MAAgCg
tfUKLOsrFjmyFu7biv7ZwVfejaMAn1QXEJw6hpvte60WZrL0CpS60A6Q
-----END RSA PUBLIC KEY-----
 
P

Piet van Oostrum

jayshree said:
j> hello ,
j> The community members,
j> Using following code :
j> fileHandle = open ('jay1key.py','wb')
j> #fileHandle = open ('jay1key.pem',rb).read()
j> print fileHandle.write (data) #data variable is contains the key
j> fileHandle.close()

j> otp = 'jyshri69'

j> pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')

[Why do you give your key file a .py extension? .pem would be better.]

Your key in the next posting (when the broken lines are reconstructed)
seems to be in PKCS1 format. That's what -----BEGIN RSA PUBLIC KEY-----
indicates. However, M2Crypto.RSA.load_pub_key expects the key in X.509
format, which starts with -----BEGIN PUBLIC KEY----- and also has a
different format inside, so just changing the header and trailer won't
work.

Anyway, I doubt that the key is correct as it seems to large for just a
public key. How was that key generated?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top