Pregunta

Estoy escribiendo un programa en Python 3 que necesita funciones de encriptación (al menos AES y RSA). He encontrado PyCrypto que parece funcionar sólo en las versiones 2.x.

¿Hay alguna buena herramienta disponible para Python 3 o debería más bien empezar a traducir mi programa para que sea compatible con Python 2 (o cualquier otra solución)?

Gracias


Actualizar como se menciona a continuación, PyCrypto ya está disponible en py3k

¿Fue útil?

Solución

PyCrypto 2.4.1 y más tarde ahora obra en Python 3.x (ver cambios diff ).

Otros consejos

A pesar de Python 3 en sí está listo para el horario estelar, la falta de bibliotecas que lo apoyan es un obstáculo. Lo mejor que puede hacer es, por supuesto, al puerto de ayuda PyCrypto a Python 3, aunque, ya que tiene una gran cantidad de módulos C-extensión que probablemente no es completamente trivial, y será un par de días de trabajo, yo creo. Tal vez el mantenedor actual está interesado en portar o ya mitad de camino, que debe ponerse en contacto con él y preguntarle.

Hay un módulo RSA escrito en Python, que parece tener código bastante limpio y fácil de transportar, pero para AES parece PyCrypto es el módulo de usar. Por lo que es probablemente más fácil de hacer que su software de correr bajo Python 2 en su lugar.

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).

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.

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.

Here is a Python3 library for cryptography research from Johns Hopkins. It supports elliptic curve operations and pairing based crypto.

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

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

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.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top