Easy to use Python encryption library/wrapper?

白昼怎懂夜的黑 提交于 2019-12-03 12:23:59

you list m2crypto, but did you see m2secret? the example at http://www.heikkitoivonen.net/m2secret/ seems pretty much exactly what you want.

disclaimer: i haven't used it and it's listed on pypi as alpha quality http://pypi.python.org/pypi/m2secret/0.1.1

update - some time after answering here i wrote simple-crypt which is a simple wrapper for pycrypto. it does aes encryption for python 2.7 and 3 and is similar to Rob's answer below but also includes PBKDF2 to generate a more secure key.

Have a look at http://code.activestate.com/recipes/576980/

EDIT

Modified to use a user-defined password of arbitrary length. Requires pyCrypto. Thrown together in minutes without a test in sight.

EDIT 2

Updated version at https://gist.github.com/1192059

I think these two packages are currently best suited: wheezy.security and SimpleAES. Both have such simple usage documented.

You could try pyOCB:

  • pure Python
  • no external dependencies
  • built-in authentication and encryption in one interface

Sample usage - encryption (and integrity protection):

(tag,ciphertext) = ocb.encrypt(plaintext, header)

Decryption and authentication:

(is_authentic, plaintext2) = ocb.decrypt(header, ciphertext, tag)

Lack of integrated message integrity protection seems to be biggest disadvantage of many other packages listed above. I've seen many production applications that were using encrypted block in URL or cookie as "secure" data storage, but could be easily manipulated because of no integrity protecion. And if the only thing you have is "encrypt with AES" library it's unlikely that you'll add HMAC validation yourself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!