
Self-contained cryptographic library for Python, classical and post-quantum
.. image:: https://github.com/Legrandin/pycryptodome/workflows/Integration%20test/badge.svg :target: https://github.com/Legrandin/pycryptodome/actions
.. image:: https://badge.fury.io/py/pycryptodome.svg :target: https://pypi.org/project/pycryptodome
PyCryptodome is a self-contained Python package of low-level
cryptographic primitives: one pip install, no system libraries,
and a broad, consistent API from AES and RSA to HPKE, KangarooTwelve and post-quantum ML-DSA and SLH-DSA.
Post-quantum: ML-DSA (FIPS 204) and SLH-DSA (FIPS 205) signatures, and, in HPKE (RFC 9180),
ML-KEM (FIPS 203) and the hybrid X-Wing, as in the draft draft-ietf-hpke-pq.
It supports Python 3.9 and newer, and PyPy.
You install it with::
pip install pycryptodome
All modules are installed under the Crypto package.
.. code-block:: python
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key = get_random_bytes(32)
cipher = AES.new(key, AES.MODE_GCM) # a random nonce is generated
ciphertext, tag = cipher.encrypt_and_digest(b"attack at dawn")
receiver = AES.new(key, AES.MODE_GCM, nonce=cipher.nonce)
plaintext = receiver.decrypt_and_verify(ciphertext, tag) # raises ValueError if tampered
.. note::
Up to version 3.x, the library was also released as the pycryptodomex
project, installed under the Cryptodome package.
Starting with version 4.0, pycryptodomex is no longer released and
Crypto is the only package name.
To migrate, replace Cryptodome with Crypto in your imports.
For the full list of algorithms and formats, see the features page.
For everything else, see the homepage.
For security issues, please send an email to [email protected].
All the code can be downloaded from GitHub_.
.. _homepage: https://www.pycryptodome.org
.. _features page: https://www.pycryptodome.org/src/features
.. _GitHub: https://github.com/Legrandin/pycryptodome