易于使用的Python加密库/包装? [英] Easy to use Python encryption library/wrapper?

查看:126
本文介绍了易于使用的Python加密库/包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Python中的密码加密任意长度的字符串。我更喜欢来处理填充,密钥生成和IVs,因为我真的不知道密码学方面的很多,我想避免混乱。我也喜欢使用一个知名的密码作为AES。



我的理想库(让我们称之为MagicCrypt)将这样工作:

  from MagicCrypt import AES 
p =plaintext
k =password
crypt = AES(k)
c = crypt.encrypt(p)
p == crypt.decrypt(c)#True

我已经检查过 PyCrypto m2crypto pycryptopp GPGme keyczar 。他们都没有提供这个非常简单易用的模式。 keyczar最接近,但是由于某种原因想要使用保存在类似文件的对象或类似的东西中的密钥集。



据我所知,我必须诉诸使用Popen调用 mcrypt ,它提供了一个完全像这样的模式 - 部分原因我猜,这真的没有技术原因不存在。 / p>

你知道Python的易于使用,安全的加密库吗?如果没有,使用任何已经提到的库最简单(但是安全)的方式是什么?

解决方案

你列出了m2crypto,但是你看到米歇尔? http://www.heikkitoivonen.net/m2secret/ 的示例似乎完全是你想要的。



免责声明:我没有使用它,它在pypi中列出为alpha质量 http://pypi.python.org/pypi/m2secret/0.1.1



更新 - 在回答这段时间后,我写了 simple-crypt ,这是一个简单的包装为pycrypto。它对python 2.7和3进行加密,类似于Rob在下面的答案,还包括PBKDF2 来生成更安全的密钥。


I want to encrypt an arbitrary-length string with a password in Python. I would prefer not to deal with padding, key generation and IVs as I honestly don't know that much about cryptography yet and I'd like to avoid messing up. I'd also prefer using a well-known cypher as AES.

My ideal library (let's call it MagicCrypt) would work like this:

from MagicCrypt import AES
p = "plaintext"
k = "password"
crypt = AES(k)
c = crypt.encrypt(p)
p == crypt.decrypt(c) # True

I've checked PyCrypto, m2crypto, pycryptopp, GPGme and keyczar. Neither of them seem to offer this really easy to use mode. keyczar comes closest, but for some reason wants to use a keyset saved in a file-like object or something similar.

As far as I know I'll have to resort to calling mcrypt with Popen, which does offer a mode that works exactly like this - part of the reason I'm guessing there's really no technical reason for this not to exist.

Do you know of an easy to use, secure, crypto library for Python? If not, what's the easiest (yet secure) way of using any of the already mentioned libraries?

解决方案

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.

这篇关于易于使用的Python加密库/包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆