Search⌘ K

PyCrypto

Explore how to use PyCrypto and its active fork PyCryptodome to handle cryptography in Python. Learn to encrypt and decrypt strings with DES, generate RSA key pairs, and perform file encryption and decryption using hybrid encryption methods. Understand padding, nonce, and secure key management.

The PyCrypto package is probably the most well known 3rd party cryptography package for Python. Sadly PyCrypto’s development stopped in 2012. Others have continued to release the latest version of PyCrypto so we can still get it for Python 3.5 if we don’t mind using a 3rd party’s binary.

Fortunately there is a fork of the project called PyCrytodome that is a drop-in replacement for PyCrypto.

You need Python 3.5 for Crypto and PyCrypto

How to install pycryptodome

To install it for Linux, we can use the following pip command:

Javascript (babel-node)
pip3 install pycryptodome

Windows is a bit different:

Javascript (babel-node)
pip3 install pycryptodomex

If we run into issues, it’s probably because we don’t have the right dependencies installed or we need a compiler for Windows.

Also worth noting is that PyCryptodome has many enhancements over the last version of PyCrypto. It is well worth our time to visit their home page and see what new features are.

Encrypting a

...