Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cryptography tools for python 3

I'm writing a program in python 3 which needs encryption functions (at least aes and rsa). I've found PyCrypto which seems to work only on 2.x versions.

Is there any good tool available for python 3 or should I rather start translating my program to be compatible with python 2 (or any other solution) ?

Thank you


Update as mentioned below, PyCrypto is now available on py3k

like image 480
Martin Trigaux Avatar asked Jan 03 '11 09:01

Martin Trigaux


4 Answers

PyCrypto 2.4.1 and later now work on Python 3.x (see changelog diff).

like image 113
dlitz Avatar answered Oct 02 '22 00:10

dlitz


Although Python 3 itself is ready for primetime, the lack of libraries that support it is a hindrance. The best you can do is of course to help port PyCrypto to Python 3, although as it has a lot of C-extension modules that is probably not entirely trivial, and will be a couple of days work, I would think. Maybe the current maintainer is interested in porting or already half-way there, you should contact him and ask.

There is an rsa module written in Python which looks to have fairly clean and easily portable code, but for aes it seems like PyCrypto is the module to use. So it is probably easier to make your software run under Python 2 instead.

like image 39
Lennart Regebro Avatar answered Oct 01 '22 23:10

Lennart Regebro


Crytographic Libraries are mostly numeric calculations and I don't know why py3k versions are not available yet.

  1. Here is pyDES available for Python 3.
  2. Here is AES algorithm implementation in Python 3. Ported from this py2k version
  3. Here is RSA algorithm implementation in Python 3. I ported it from this py2k version.

Please use them with caution as they just development programs implemented following the algorithm text. (That is, I am not sure of the rigor in the original python2 version). Also, all of them are pure python libraries, they would be slower than anything written using C-extensions ( and perhaps that is the reason, why py3k versions are getting delayed).

like image 5
Senthil Kumaran Avatar answered Oct 01 '22 23:10

Senthil Kumaran


i have written a wrapper library simple-crypt that provides encryption and decryption in python 3, delegating the work to pycrypto.

advantages of using this over pycrypto directly include:

  • much simpler interface:

    data = encrypt(password, text)
    text = decrypt(password, data).decode('utf8')
    
  • key expansion to make the use of passphrases more secure

  • use of an hmac to check for modification of the data

  • a versioned header that should allow me to switch the implementation to google's keyczar once that moves to python 3 (since that should be better maintained - i only wrote this out of apparent necessity).

you can install the package using:

easy_install simple_crypt

more info available on the github page for the project.

like image 4
andrew cooke Avatar answered Oct 01 '22 23:10

andrew cooke