views:

120

answers:

2

Consider the code:

fileHandle = open ( 'test8.pem','w' )
fileHandle.write (data)

pub_key = M2Crypto.RSA.load_pub_key(open('test8.pem'))

Error coming like :

 File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 343, in load_pub_key
bio = BIO.openfile(file) 
  File "/usr/lib/python2.4/site-packages/M2Crypto/BIO.py", line 186, in openfile
    return File(open(filename, mode))
IOError: [Errno 2] No such file or directory: ''

what wrong in the way i use ? My query is how do I pass the file into load_pub_key method so it can be accessible by simply passing the file name ?

A: 

If you pass test8.pem without quotes, Python interprets it as the name of a variable, which is not defined, hence the error.

I don't know the specific library you are using but I would guess that you need to pass fileHandle instead.

UncleZeiv
A: 

this should work for you:

fname = 'test8.pem'
fileHandle = open(fname, 'w')
fileHandle.write(data)
fileHandle.close()
pub_key = M2Crypto.RSA.load_pub_key(fname)
SilentGhost
thanks its seems cool but after applying this code again error :Traceback (most recent call last): File "RetEnc.py", line 17, in ? pub_key = M2Crypto.RSA.load_pub_key(fname) 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
so content of your file is malformed. and it's outside of the scope of this question.
SilentGhost