PyCrypto
PyCrypto is a collection of cryptographic modules for Python, providing algorithms like AES, RSA, and hashing functions. Its last release was 2.6.1 in 2013. The library is unmaintained and is considered insecure for modern applications due to known vulnerabilities and lack of updates. Its development has ceased, with `pycryptodome` serving as its actively maintained successor and drop-in replacement.
Warnings
- breaking PyCrypto is not actively maintained and has known security vulnerabilities, including side-channel attacks and issues with various primitives. Its usage is highly discouraged for any new or security-sensitive applications.
- gotcha Official PyCrypto (v2.6.1) has limited and problematic Python 3 support. Installation often fails on modern Python environments and requires system-level build dependencies (like `gcc`, `python-dev`, `build-essential`) that might not be present by default.
- deprecated PyCrypto is considered an abandoned library; its last release was in 2013. Its APIs are outdated compared to modern cryptographic practices, and it lacks support for newer, more secure algorithms and modes.
Install
-
pip install pycrypto
Imports
- AES
from Crypto.Cipher import AES
- RSA
from Crypto.PublicKey import RSA
- MD5
from Crypto.Hash import MD5
- Python 3 compatibility
from Cryptodome.Cipher import AES # For pycryptodome
Quickstart
from Crypto.Hash import MD5
import os
# Note: PyCrypto is an abandoned library and not recommended for new projects
# due to security concerns. This example is for illustrative purposes only.
# For production, use pycryptodome or cryptography.
try:
message = b"This is a test message to hash."
# Create an MD5 hash object
hasher = MD5.new()
hasher.update(message)
print(f"Original message: {message}")
print(f"MD5 hash (hex): {hasher.hexdigest()}")
# Important security note: MD5 is cryptographically broken and should NOT
# be used for security-critical applications like password storage or digital signatures.
except ImportError:
print("PyCrypto is not installed or unable to import modules. Please ensure 'pip install pycrypto' was successful and check Python version compatibility.")
except Exception as e:
print(f"An error occurred: {e}")