unicrypto
raw JSON → 0.0.12 verified Fri May 01 auth: no python
Unified interface for cryptographic libraries in Python. Current version 0.0.12 provides a consistent API across backends like cryptography, pycryptodome, and hashlib. Release cadence is sporadic; last update 2022.
pip install unicrypto Common errors
error ModuleNotFoundError: No module named 'unicrypto.symmetric' ↓
cause Trying to import from a submodule that doesn't exist directly; unicrypto exposes symmetric classes at top level.
fix
Use from unicrypto import symmetric (this works) or from unicrypto import Cipher.
error AttributeError: 'Ciphertext' object has no attribute 'hex' ↓
cause Cipher.encrypt returns a Ciphertext object, not bytes. You need to access .data to get bytes.
fix
Use ciphertext.data.hex() instead of ciphertext.hex().
error ValueError: Invalid key size for AES ↓
cause Provided key length not supported by AES (16, 24, or 32 bytes).
fix
Ensure key is 16, 24, or 32 bytes for AES-128, AES-192, or AES-256 respectively.
Warnings
breaking Version 0.0.10 changed the return type of Cipher.encrypt from bytes to Ciphertext object. Access bytes via .data property. ↓
fix Use ciphertext.data instead of treating ciphertext as bytes.
gotcha Many examples use from unicrypto.symmetric import AES which is incorrect; AES is accessed via Cipher with algorithm string 'aes'. ↓
fix Use from unicrypto import Cipher; cipher = Cipher('aes', ...)
deprecated The PKCS7 padding class is deprecated in favor of integrated padding in Cipher mode. ↓
fix Use Cipher with padding parameter or rely on default padding.
Imports
- Cipher
from unicrypto import Cipher - PKCS1_v1_5 wrong
from unicrypto.symmetric import PKCS1_v1_5 (wrong path)correctfrom unicrypto import PKCS1_v1_5
Quickstart
from unicrypto import Cipher, symmetric
import os
key = os.environ.get('KEY', '00112233445566778899aabbccddeeff')
iv = os.environ.get('IV', 'fedcba9876543210')
cipher = Cipher(b'aes', key=bytes.fromhex(key), iv=bytes.fromhex(iv))
plaintext = b'secret message'
ciphertext = cipher.encrypt(plaintext)
print(ciphertext.hex())