PyCryptodomeX is a self-contained Python package providing low-level cryptographic primitives. It is a fork of the unmaintained PyCrypto library, offering numerous enhancements like authenticated encryption modes, Hybrid Public Key Encryption (HPKE), accelerated AES, and elliptic curve cryptography. It is actively maintained, with version 3.23.0 being the latest, and releases occur frequently. It supports Python 2.7, Python 3.7 and newer, and PyPy.
pip install pycryptodomexVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates symmetric encryption and decryption using AES in CBC mode with PyCryptodomeX. It covers key and IV generation, data padding, encryption, and subsequent decryption and unpadding.
Upgrade Python to 3.7+ or pin pycryptodomex to <3.22.0.
Always use `from Cryptodome.<module> import <Symbol>` for `pycryptodomex` installations.
Always explicitly specify a secure mode of operation, such as `AES.MODE_CBC`, `AES.MODE_GCM`, or `AES.MODE_EAX`, during cipher initialization (e.g., `AES.new(key, AES.MODE_CBC, iv)`). If ECB is truly intended (rarely), use `AES.new(key, AES.MODE_ECB)`.
Upgrade to PyCryptodomeX 3.19.1 or newer to mitigate this side-channel attack.
Ensure that the data length used with CCM ciphers is compatible with the chosen nonce length to avoid early termination. Consult documentation for specific limits.
Upgrade to PyCryptodomeX 3.22.0 or newer if using RC4 with large data, or consider using a more modern stream cipher.
If you installed `pycryptodomex`, change your import statements to use `Cryptodome` instead of `Crypto` (e.g., `from Cryptodome.Cipher import AES`). If you intended to use the `Crypto` namespace, install `pycryptodome` instead (`pip install pycryptodome`).
If you installed `pycryptodome`, change your import statements to use `Crypto` instead of `Cryptodome` (e.g., `from Crypto.Cipher import AES`). If you intended to use the `Cryptodome` namespace, ensure `pycryptodomex` is correctly installed (`pip install pycryptodomex`) and check for environment conflicts.
Install the appropriate C++ build tools for your Python version and operating system. On Windows, this typically means installing 'Build Tools for Visual Studio' (e.g., from visualstudio.microsoft.com) and selecting the C++ development workload.
Ensure that encrypted data is handled as raw bytes. If you need to transmit encrypted data as a string (e.g., over HTTP), first encode the bytes using a binary-to-text encoding like Base64 (`import base64; base64.b64encode(ciphertext)`). On receipt, decode from Base64 back to bytes *before* attempting decryption (`base64.b64decode(encoded_ciphertext)`).
No dependency data recorded yet.