Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 384
Daren Thomas Avatar asked Oct 05 '08 19:10

Daren Thomas


People also ask

How do you do AES encryption in Python?

the AES 256 Using PyCrypto in Python Padding is done before encryption. After decryption, we un-pad the ciphertext to discard the additional bytes and get the original message. Here, we have made two functions, encrypt and decrypt , which use the AES technique.

Is it possible to crack AES 256 encryption?

AES 256 is virtually impenetrable using brute-force methods. While a 56-bit DES key can be cracked in less than a day, AES would take billions of years to break using current computing technology. Hackers would be foolish to even attempt this type of attack. Nevertheless, no encryption system is entirely secure.

What programs use AES encryption?

The National Security Agency (NSA) and many other U.S. government entities, including the military, use AES encryption for encrypted communications and secure data storage daily. LastPass, a password management service, uses AES encryption to keep its users' passwords safe from hackers and even LastPass employees.

Is AES 256 encryption end to end?

End-to-end encryption works in two different ways: symmetric or asymmetric. Symmetric encryption encodes data and offers the greatest possible security through AES-256 encryption. However, this also requires the AES-256 key itself to be transmitted securely and confidentially.


2 Answers

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.

like image 185
friol Avatar answered Oct 11 '22 13:10

friol


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.

like image 42
caller9 Avatar answered Oct 11 '22 13:10

caller9