What (pure) Python library to use for AES 256 encryption?

31,868

Solution 1

PyCrypto should be the one for you.

Edit 02/10/2020: unfortunately I cannot delete this post, since it's the accepted answer. As people pointed out in the comments, this library is not mantained anymore and probably also vulnerable from a security point of view. So please, take a look to the below answers instead.

Solution 2

https://github.com/caller9/pythonaes

That is pure python with PKCS7 padding. Supports CBC, CFB, and OFB modes.

The problem is that python is not super fast for this type of thing. The code from serprex's fork is a little bit inscrutable, but much faster than mine due to using all kinds of tricks to squeeze every last bit of speed out of Python.

Really though, the best libraries for this are compiled and hook into SSE/MMX stuff.

Also Intel is baking in AES instructions since the Core(tm) line of chips.

I wrote my version to get a true pure Python version out there to be able to run on any architecture, cross-platform, and with 3.x as well as 2.7.

Solution 3

Since I found this question when searching for the same thing I would like to add another one to the list:

SlowAEShttp://code.google.com/p/slowaes/
It's a development of Josh Davis' code, with the help of some other people. It seems to work fine.

Solution 4

How about ncrypt? It's not pure python but it is a lot faster as a result. It is basically a nice python wrapper on OpenSSL, so you know there's quality code behind it.

Solution 5

PyCrypto is not clearly pythonic so you can get troubles compiling it on some platforms (AIX, HP-UX etc)

Share:
31,868
darkAsPitch
Author by

darkAsPitch

I am an software developer that is not afraid to get his hands dirty... I done time in Visual Basic and never complained. PHP? Sure. I can write beautiful code in any language. But Python really rocks my boat. And c# I like too. I tend to collect a lot of different tools and am especially fond of those that work well together - as opposed to technologies that tend to create silos with NIHS. As I mature as a software developer, I have found that my passion for the craft grows while at the same time my willingness to participate in flame wars shrinks. Let's just get it done. And make the user happy.

Updated on December 17, 2020

Comments

  • darkAsPitch
    darkAsPitch over 3 years

    I am looking for a (preferably pure) python library to do AES 256 encryption and decryption.

    This library should support the CBC cipher mode and use PKCS7 padding according to the answer to an earlier question of mine.

    The library should at least work on Mac OS X (10.4) and Windows XP. Ideally just by dropping it into the source directory of my project. I have seen this by Josh Davis, but am not sure about how good it is and if it does the required CBC cipher mode... Scanning the source suggests it doesn't