simple-crypt

raw JSON →
4.1.7 verified Mon Apr 27 auth: no python maintenance

Simple, secure encryption and decryption for Python 2.7 and 3. Current version 4.1.7. Provides high-level functions `encrypt` and `decrypt` using PBKDF2 and AES-256-CBC. Release cadence is low (last release 2018).

pip install simple-crypt
error TypeError: password must be a string, not bytes
cause Passing bytes as password in Python 3. The library strictly requires str.
fix
Use password = 'my-password' (str) instead of b'my-password'.
error ImportError: No module named 'Crypto'
cause Missing or incompatible pycryptodome installation.
fix
Install pycryptodome: pip install pycryptodome. For compatibility issues, pin version: pip install 'pycryptodome==3.9.9'
error ValueError: PEM encryption failed
cause Decryption with wrong password or corrupted ciphertext.
fix
Ensure the password is correct and the ciphertext has not been altered.
breaking In Python 3, password must be a string (not bytes). Passing bytes as password raises TypeError.
fix Always use str for password: encrypt('password', data) not encrypt(b'password', data).
breaking Library has known issues with pycryptodome versions >3.9.9. Installation may conflict with newer pycryptodome releases.
fix Pin pycryptodome to 3.9.9: pip install 'pycryptodome==3.9.9'

Encrypt and decrypt using a password string. Data must be bytes-like.

from simplecrypt import encrypt, decrypt

# Encrypt
password = 'my-secret-password'
plaintext = b'Hello, this is secret data'
ciphertext = encrypt(password, plaintext)
print(ciphertext)

# Decrypt
plaintext_back = decrypt(password, ciphertext)
print(plaintext_back)

# Note: password must be a string, data must be bytes-like.