python 3 的密码学工具

发布于 2024-10-10 09:44:28 字数 289 浏览 8 评论 0原文

我正在用 python 3 编写一个程序,它需要加密函数(至少 aes 和 rsa)。我发现 PyCrypto 似乎只适用于 2.x 版本。

有没有适用于 python 3 的好工具,或者我应该开始翻译我的程序以与 python 2 (或任何其他解决方案)兼容?

谢谢


更新,如下所述,PyCrypto 现已在 py3k 上可用

I'm writing a program in python 3 which needs encryption functions (at least aes and rsa). I've found PyCrypto which seems to work only on 2.x versions.

Is there any good tool available for python 3 or should I rather start translating my program to be compatible with python 2 (or any other solution) ?

Thank you


Update as mentioned below, PyCrypto is now available on py3k

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

那请放手 2024-10-17 09:44:29

pycrypto 有 Py3k 分支(位于 https://github.com/dlitz/pycrypto/tree/py3k)

pycrypto has Py3k branch (in https://github.com/dlitz/pycrypto/tree/py3k)

箜明 2024-10-17 09:44:28

PyCrypto 2.4.1 及更高版本现在可在 Python 3.x 上运行(请参阅变更日志差异)。

PyCrypto 2.4.1 and later now work on Python 3.x (see changelog diff).

风追烟花雨 2024-10-17 09:44:28

尽管 Python 3 本身已准备好迎接黄金时期,但缺乏支持它的库是一个障碍。当然,你能做的最好的事情就是帮助将 PyCrypto 移植到 Python 3,尽管它有很多 C 扩展模块,这可能并不完全是微不足道的,我认为这将是几天的工作。也许当前的维护者对移植感兴趣或者已经进行了一半,您应该联系他并询问。

有一个用 Python 编写的 rsa 模块,看起来有相当干净且易于移植的代码,但对于 aes 来说,似乎 PyCrypto 是要使用的模块。因此,让您的软件在 Python 2 下运行可能更容易。

Although Python 3 itself is ready for primetime, the lack of libraries that support it is a hindrance. The best you can do is of course to help port PyCrypto to Python 3, although as it has a lot of C-extension modules that is probably not entirely trivial, and will be a couple of days work, I would think. Maybe the current maintainer is interested in porting or already half-way there, you should contact him and ask.

There is an rsa module written in Python which looks to have fairly clean and easily portable code, but for aes it seems like PyCrypto is the module to use. So it is probably easier to make your software run under Python 2 instead.

聆听风音 2024-10-17 09:44:28

密码库主要是数值计算,我不知道为什么 py3k 版本还没有可用。

  1. 这是可用于 Python 3 的 pyDES
  2. 这是 Python 3 中的 AES 算法 实现。从此 py2k 版本
  3. 这是 RSA 算法 Python 3 中的实现。我从这个 py2k 版本 移植了它。

请谨慎使用它们,因为它们只是按照算法文本实现的开发程序。 (也就是说,我不确定原始python2版本的严谨性)。
此外,它们都是纯 python 库,它们比使用 C 扩展编写的任何库都要慢(也许这就是 py3k 版本延迟的原因)。

Crytographic Libraries are mostly numeric calculations and I don't know why py3k versions are not available yet.

  1. Here is pyDES available for Python 3.
  2. Here is AES algorithm implementation in Python 3. Ported from this py2k version
  3. Here is RSA algorithm implementation in Python 3. I ported it from this py2k version.

Please use them with caution as they just development programs implemented following the algorithm text. (That is, I am not sure of the rigor in the original python2 version).
Also, all of them are pure python libraries, they would be slower than anything written using C-extensions ( and perhaps that is the reason, why py3k versions are getting delayed).

圈圈圆圆圈圈 2024-10-17 09:44:28

我编写了一个包装库 simple-crypt ,它在 python 3 中提供加密和解密,委托pycrypto 的工作。

与直接使用 pycrypto 相比,使用它的优点包括:

  • 界面更简单:

    data = 加密(密码,文本)
    文本 = 解密(密码, 数据).decode('utf8')
    
  • 密钥扩展使密码短语的使用更加安全

  • 使用 hmac 来检查修改数据

  • 版本化标头,一旦迁移到 python 3,它应该允许我将实现切换到 google 的 keyczar(因为应该更好地维护 - 我只是出于明显的必要性才写了这个)。

您可以使用以下方法安装该软件包:

easy_install simple_crypt

该项目的 github 页面上提供了更多信息。

i have written a wrapper library simple-crypt that provides encryption and decryption in python 3, delegating the work to pycrypto.

advantages of using this over pycrypto directly include:

  • much simpler interface:

    data = encrypt(password, text)
    text = decrypt(password, data).decode('utf8')
    
  • key expansion to make the use of passphrases more secure

  • use of an hmac to check for modification of the data

  • a versioned header that should allow me to switch the implementation to google's keyczar once that moves to python 3 (since that should be better maintained - i only wrote this out of apparent necessity).

you can install the package using:

easy_install simple_crypt

more info available on the github page for the project.

缘字诀 2024-10-17 09:44:28

密码学 (文档)声称解决了 PyCryptoM2Crypto 和PyOpenSSL。他们没有提到 simple-crypt,但该项目的主要目标是提供高级、安全、易于使用的接口以及一组较低级接口(可从 ' hazmat' 模块)允许了解陷阱的开发人员进行更细粒度的控制。

由于没有使用其他库,我无法评论密码学是否比其他库更好,但到目前为止它确实满足了我的需求。

Cryptography (documentation) claims to address multiple shortcomings of PyCrypto, M2Crypto, and PyOpenSSL. They don't mention simple-crypt, but a primary goal of the project is to provide high-level, safe, easy to use interfaces along with a set of lower-level interfaces (available from a 'hazmat' module) allowing finer-grained control for developers who understand the pitfalls.

Having not used the other libraries I can't comment on whether cryptography is better than the alternatives, but it has certainly met my needs so far.

小耗子 2024-10-17 09:44:28

我不知道有任何合理的 python 加密库(无论版本如何)。我所知道的一切(包括 pycrypto)都只是一个玩具。如果您想实现一个严肃的应用程序,那么您应该寻找真正的库(例如 m2crypto)的包装器。 Pycrypto 本身确实遵循许多标准。
特别是,RSA 需要良好的填充方案才能保证安全。由于 pycrypto 至少目前没有使用
填充,这使得它的 RSA 实现相当不安全并且与其他加密库不兼容。

回答马丁的问题:显然这个问题可以接受很多意见。一项建议是使用 Java 而不是 python。 Java 有一个定义良好的加密接口,并且有不同的提供者实现该接口。这样做有一个相当大的优势,即可以实现独立于提供商的解决方案,以便可以轻松地在不同提供商之间切换。我个人喜欢openssl,但我知道它很难使用。

I'm not aware of any reasonable crypto library for python (regardless of the version). Everything I'm aware of (including pycrypto) is just a toy. If you want to implement a serious application then you should look for a wrapper to a real library such as m2crypto. Pycrypto itself does follow many standards.
Especially, RSA needs a good padding scheme to be secure. Since pycrypto is at least currently not using
a padding, this makes its RSA implementation both rather insecure and incompatible with other crypto libraries.

Answer to Martins question: Obviously this question is open to a lot of opinions. One proposal would be to use Java instead of python. Java has a well defined cryptographic interface, and there are different providers that implement the interface. This has the rather big advantage, that one can implement a solution independent of the provider, so that one can easily switch between different providers. I personally like openssl, but I'm aware that it is rather difficult to use.

童话里做英雄 2024-10-17 09:44:28

我的 LibTomCrypt 周围的 Python 包装器现在支持 Python 3,并且它具有 AES 和 RSA。

请参阅:https://github.com/mikeboers/PyTomCrypt#readme

My Python wrapper around LibTomCrypt now supports Python 3, and it has both AES and RSA.

See: https://github.com/mikeboers/PyTomCrypt#readme

沦落红尘 2024-10-17 09:44:28

Charm 是约翰·霍普金斯大学用于快速构建高级密码系统原型的框架。
它支持椭圆曲线运算和基于配对的密码学。

该文档位于 Charm-Crypto 0.50 文档

Charm is a framework for rapidly prototyping advanced cryptosystems from Johns Hopkins.
It supports elliptic curve operations and pairing based cryptography.

The documentation is available on Charm-Crypto 0.50 documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文