PyCryptodomeΒΆ
PyCryptodome is a self-contained Python package of low-level
cryptographic primitives, for Python 3.9 and newer.
It needs no system libraries: install it with pip install pycryptodome.
For instance, this is how to encrypt and authenticate a message with AES in GCM mode, and then decrypt it:
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key = get_random_bytes(32)
cipher = AES.new(key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(b"Attack at dawn")
# The receiver needs the key, the nonce, the ciphertext and the tag
cipher = AES.new(key, AES.MODE_GCM, nonce=cipher.nonce)
plaintext = cipher.decrypt_and_verify(ciphertext, tag)
Where to go next:
Installation, for the details of the installation.
API documentation, for all the algorithms, grouped by package.
Examples, for complete examples of common tasks.
Frequently Asked Questions, for the most frequent questions.