易于使用的Python加密库/包装?

编程入门 行业动态 更新时间:2024-10-15 20:25:23
本文介绍了易于使用的Python加密库/包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想用Python中的密码加密任意长度的字符串。我更喜欢不来处理填充,密钥生成和IVs,因为我真的不知道密码学方面的很多,我想避免混乱。我也喜欢使用一个知名的密码作为AES。

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

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

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

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

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

解决方案

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

免责声明:我没有使用它,它在pypi中列出为alpha质量 pypi.python/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 www.heikkitoivonen/m2secret/ seems pretty much exactly what you want.

disclaimer: i haven't used it and it's listed on pypi as alpha quality pypi.python/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加密库/包装?

本文发布于:2023-11-02 04:02:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!