735
PyCryptodome is a self-contained Python package of low-level cryptographic primitives.
PyCryptodome is a fork of PyCrypto. It brings the following enhancements with respect to the last official version of PyCrypto (2.6.1):
- Authenticated encryption modes (GCM, CCM, EAX, SIV, OCB)
- Accelerated AES on Intel platforms via AES-NI
- First class support for PyPy
- Elliptic curves cryptography (NIST P-curves; Ed25519, Ed448)
- Better and more compact API (nonce and iv attributes for ciphers, automatic generation of random nonces and IVs, simplified CTR cipher mode, and more)
- SHA-3 hash algorithms (FIPS 202) and derived functions (NIST SP-800 185):
- SHAKE128 and SHA256 XOFs
- cSHAKE128 and cSHAKE256 XOFs
- KMAC128 and KMAC256
- TupleHash128 and TupleHash256
- KangarooTwelve XOF (derived from Keccak)
- Truncated hash algorithms SHA-512/224 and SHA-512/256 (FIPS 180-4)
- BLAKE2b and BLAKE2s hash algorithms
- Salsa20 and ChaCha20/XChaCha20 stream ciphers
- Poly1305 MAC
- ChaCha20-Poly1305 and XChaCha20-Poly1305 authenticated ciphers
- scrypt, bcrypt, HKDF, and NIST SP 800 108r1 Counter Mode key derivation functions
- Deterministic (EC)DSA and EdDSA
- Password-protected PKCS#8 key containers
- Shamir’s Secret Sharing scheme
- Random numbers get sourced directly from the OS (and not from a CSPRNG in userspace)
- Simplified install process, including better support for Windows
- Cleaner RSA and DSA key generation (largely based on FIPS 186-4)
- Major clean ups and simplification of the code base
Install PyCryptodome library from the command line:
pip install pycryptodome
Generate SHA-512/256 hash:
from Crypto.Hash import SHA512 text = 'Hello from maxpython' hashObject = SHA512.new(truncate='256') hashObject.update(text.encode('utf-8')) digest = hashObject.hexdigest() print(digest)
I saw this in the repl window
>> %Run code.py
f3f72adc4464abc57f414018d0627a299a44561d5372686fe306884affede581
Generate SHA-512/224 hash:
from Crypto.Hash import SHA512 text = 'Hello from maxpython' hashObject = SHA512.new(truncate='224') hashObject.update(text.encode('utf-8')) digest = hashObject.hexdigest() print(digest)
I saw this in the repl window
>> %Run code.py
f83f0c4b39c41f399f4531e8ff37a18d329b3f1e0e32f7d4bae267bb