RSA in python

2006-02-17 Thread Abhisek Datta
Hello,

I am looking for good RSA implementations in python that can import a
public key in PEM format and encrypt a buffer using the imported
public key. I tried m2crypto, but somehow it is giving me exceptions
which I couldnt solve as of now.

I get the following with m2crypto:
rsa = M2Crypto.RSA.load_pub_key("pubkey.pem")
gives me:
  File "KB_Client.py", line 63, in SessionInit
rsa = M2Crypto.RSA.load_pub_key("pubkey.pem")
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 225,
in load_pub_key
return load_pub_key_bio(bio)
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 237,
in load_pub_key_bio
rsa_error()
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 162,
in rsa_error
raise RSAError, m2.err_reason_error_string(m2.err_get_error())
M2Crypto.RSA.RSAError: no start line


Any help will be highly appreciated.

Regards,
-abhisek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RSA in python

2006-02-17 Thread Abhisek Datta
I tried the ezPyCrypto which is basically a higher level wrapper to pyCrypto
but it fails to import public key in PEM format.

-abhisek

On 17 Feb 2006 07:02:51 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Did you try this: http://www.amk.ca/python/code/crypto ?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RSA in python

2006-02-17 Thread Abhisek Datta
Hello,

Here is some debugging output:

---
pyKB-DEBUG: Connecting to http://192.168.0.2:8080/RPC2
pyKB-DEBUG: Initializing session: (sessionKey: ABCDEFGHIJKLMNO)
pyKB-DEBUG: Received public key:
-BEGIN RSA PUBLIC KEY-
MIGJAoGBALxi3tGXlSwRgn7/Km6mTSge+5ijQgIn3GvnZOeYyOo1DkubVtTaFj26
GWtJo43MEe1a5UlWKJEOpbKVCr4AASfFj8YmmRewH4SXdZ+w1Bad8amyzL2h8F7J
wJojOnocSs6xDE7o86CpZRUlojBefanMdCpu074QFktE63OD1zBBAgMBAAE=
-END RSA PUBLIC KEY-

Traceback (most recent call last):
  File "KB_Client.py", line 96, in ?
kb.SessionInit(sessionKey="ABCDEFGHIJKLMNO")
  File "KB_Client.py", line 63, in SessionInit
rsa = M2Crypto.RSA.load_pub_key("pubkey.pem")
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 225,
in load_pub_key
return load_pub_key_bio(bio)
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 237,
in load_pub_key_bio
rsa_error()
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 162,
in rsa_error
raise RSAError, m2.err_reason_error_string(m2.err_get_error())
M2Crypto.RSA.RSAError: no start line
---

You can clearly see the public key which I am receiving from an xmlrpc
server. Then I saved the public key in "pubkey.pem" file and then use
M2Crypto.RSA.load_pub_key() and I am getting the output as show above.

-abhisek

On 2/17/06, Heikki Toivonen <[EMAIL PROTECTED]> wrote:
> Abhisek Datta wrote:
> > I am looking for good RSA implementations in python that can import a
> > public key in PEM format and encrypt a buffer using the imported
> > public key. I tried m2crypto, but somehow it is giving me exceptions
> > which I couldnt solve as of now.
>
> What you are trying to do should be covered by M2Crypto. Without more
> context for the error (what was the file you were trying load, etc.) it
> is hard to say what is wrong. My first guess is that your pem file did
> not include the BEGIN/END lines.
>
> I would suggest you take a look at the tests and samples included in
> M2Crypto. They do show how to work with PEM files.
>
>
> M2Crypto 0.15: http://wiki.osafoundation.org/bin/view/Projects/MeTooCrypto
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list