Jasypt-like encryption library for Python - Encrypt your configuration with ENC(...) pattern
Project description
PyCrypt ๐
Jasypt-like encryption library for Python - Encrypt your application configuration with the familiar ENC(...) pattern used in Spring Boot applications.
Made with โค๏ธ from Claude AI for Python developers who need Jasypt
๐ฏ Why PyCrypt?
If you're coming from Java/Spring Boot world and need to share encrypted configuration with Python applications, PyCrypt is for you! It provides:
- โ
Familiar
ENC(...)pattern - Just like Jasypt in Spring Boot - โ Java Jasypt compatibility - Decrypt values encrypted by Java
- โ Multiple encryption algorithms - From legacy Jasypt to modern AES-256-GCM
- โ Config file loaders - Load .env, YAML, JSON with auto-decryption
- โ CLI tool included - Encrypt/decrypt from command line
- โ Cross-platform - Works with GoCrypt (Go) and Java Jasypt
๐ฆ Installation
pip install pycrypt-jasypt
๐ Quick Start
Basic Encryption/Decryption
from pycrypt import Encryptor
# Create encryptor with password
enc = Encryptor("mySecretPassword")
# Encrypt
encrypted = enc.encrypt_with_prefix("db_password_123")
print(encrypted) # ENC(base64encodedvalue...)
# Decrypt
decrypted = enc.decrypt_prefixed(encrypted)
print(decrypted) # db_password_123
Loading Encrypted Configuration
from pycrypt import ConfigLoader
import os
# .env file:
# DATABASE_HOST=localhost
# DATABASE_PASSWORD=ENC(AbCdEf123456...)
loader = ConfigLoader(os.getenv("PYCRYPT_PASSWORD"))
config = loader.load_env_file(".env")
print(config["DATABASE_PASSWORD"]) # actual_password
๐ Encryption Algorithms
| Encryptor | Algorithm | Security | Use Case |
|---|---|---|---|
Encryptor |
AES-256-GCM | โญโญโญโญโญ | Recommended for new projects |
JasyptStrongEncryptor |
PBEWithHmacSHA256AndAES_256 | โญโญโญโญ | Jasypt strong compatibility |
JasyptEncryptor |
PBEWithMD5AndDES | โญโญ | Legacy Jasypt compatibility |
Choose the Right Algorithm
from pycrypt import Encryptor, JasyptEncryptor, JasyptStrongEncryptor
# RECOMMENDED: For new Python projects
enc = Encryptor(password)
# For compatibility with Java Jasypt (default algorithm)
enc = JasyptEncryptor(password)
# For compatibility with Java Jasypt (strong encryption)
enc = JasyptStrongEncryptor(password)
โ Java Jasypt Compatibility
โ ๏ธ Important: Compatibility Matrix
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ENCRYPT WITH โ DECRYPT WITH โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Java Jasypt (default) โ JasyptEncryptor โ
YES โ
โ Java Jasypt (strong) โ JasyptStrongEncryptor โ
YES โ
โ Java Jasypt (default) โ Encryptor โ NO โ
โ Encryptor โ Java Jasypt โ NO โ
โ JasyptEncryptor โ Java Jasypt โ
YES โ
โ GoCrypt JasyptEnc โ JasyptEncryptor โ
YES โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Decrypt Values from Java
from pycrypt import JasyptEncryptor
# Your Java application.properties has:
# db.password=ENC(xxxFromJavaxxx)
enc = JasyptEncryptor(same_password_as_java)
decrypted = enc.decrypt_prefixed("ENC(xxxFromJavaxxx)") # โ
Works!
Share Config with Go (GoCrypt)
from pycrypt import JasyptEncryptor
# Use JasyptEncryptor so both Python and Go can read
enc = JasyptEncryptor(shared_password)
encrypted = enc.encrypt_with_prefix("shared_secret")
# This ENC(...) value can be decrypted by:
# - Python: using JasyptEncryptor
# - Go: using gocrypt.NewJasyptEncryptor
# - Java: using Jasypt library
๐ Usage Guide
Configuration Files
.env File
# config.env
DATABASE_HOST=localhost
DATABASE_PASSWORD=ENC(AbCdEf123456...)
API_KEY=ENC(XyZ789...)
from pycrypt import ConfigLoader
loader = ConfigLoader(password)
config = loader.load_env_file("config.env")
print(config["DATABASE_PASSWORD"]) # decrypted value
JSON File
config = loader.load_json("config.json")
Set to Environment Variables
loader.set_to_env(".env")
# Now use os.getenv()
db_password = os.getenv("DATABASE_PASSWORD")
Decrypt Map
config = {
"host": "localhost",
"password": "ENC(encrypted_value)",
}
decrypted = enc.decrypt_map(config)
print(decrypted["password"]) # plaintext
Check if Value is Encrypted
from pycrypt import is_encrypted
if is_encrypted(value):
decrypted = enc.decrypt_prefixed(value)
๐ป CLI Tool
Usage
# Encrypt a value
pycrypt encrypt -p mySecret -v "database_password"
# Output: ENC(base64value...)
# Decrypt a value
pycrypt decrypt -p mySecret -v "ENC(base64value...)"
# Output: database_password
# Encrypt all values in a file
pycrypt encrypt-file -p mySecret -i .env.plain -o .env.encrypted
# Decrypt all values in a file
pycrypt decrypt-file -p mySecret -i .env.encrypted -o .env.plain
# Use Jasypt-compatible algorithm
pycrypt encrypt -p mySecret -v "secret" --jasypt
# Use environment variable for password
export PYCRYPT_PASSWORD=mySecret
pycrypt encrypt -v "secret_value"
โ๏ธ Advanced Configuration
Custom Options
# Encryptor (AES-256-GCM)
enc = Encryptor(
password,
iterations=50000, # default: 10000
salt_size=32, # default: 16
key_size=32, # 32 = AES-256
)
# Jasypt Compatible
enc = JasyptEncryptor(
password,
iterations=2000, # default: 1000
)
# Jasypt Strong
enc = JasyptStrongEncryptor(
password,
iterations=5000,
salt_size=32,
)
๐ก๏ธ Security
Best Practices
- Never hardcode passwords - Use environment variables
- Rotate passwords regularly
- Use strong passwords (minimum 16 characters)
- Use
Encryptorfor new projects - More secure than Jasypt algorithms
๐ API Reference
Encryptor
enc = Encryptor(password, iterations=10000, salt_size=16, key_size=32)
encrypted = enc.encrypt(plaintext) # Returns base64
encrypted = enc.encrypt_with_prefix(plaintext) # Returns ENC(base64)
plaintext = enc.decrypt(base64_string)
plaintext = enc.decrypt_prefixed("ENC(...)")
decrypted_str = enc.decrypt_all_in_string(config_string)
decrypted_map = enc.decrypt_map({"key": "ENC(...)"})
JasyptEncryptor
enc = JasyptEncryptor(password, iterations=1000)
# Same methods as Encryptor
JasyptStrongEncryptor
enc = JasyptStrongEncryptor(password, iterations=1000, salt_size=16)
# Same methods as Encryptor
ConfigLoader
loader = ConfigLoader(password)
config = loader.load_env_file(".env")
config = loader.load_yaml("config.yaml")
config = loader.load_json("config.json")
loader.set_to_env(".env")
Utility Functions
from pycrypt import is_encrypted
is_encrypted("ENC(abc)") # True
is_encrypted("plaintext") # False
๐ Project Structure
pycrypt/
โโโ src/pycrypt/
โ โโโ __init__.py # Package exports
โ โโโ encryptor.py # AES-256-GCM encryption
โ โโโ jasypt_compat.py # Jasypt compatibility
โ โโโ config_loader.py # Config file loader
โ โโโ cli.py # CLI tool
โ โโโ utils.py # Utility functions
โโโ tests/
โ โโโ test_encryptor.py
โ โโโ test_jasypt_compat.py
โโโ pyproject.toml
โโโ README.md
โโโ LICENSE
โโโ CLAUDE.md
๐งช Testing
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=pycrypt
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Related Projects
Made with โค๏ธ from Claude AI for Python developers who need Jasypt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycrypt_jasypt-1.0.0.tar.gz.
File metadata
- Download URL: pycrypt_jasypt-1.0.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
151da0d363ee837480304ec2b6b5615470635d1095af03d38a86694d8bb866fc
|
|
| MD5 |
a7570a428929d521291d4df75728d075
|
|
| BLAKE2b-256 |
2bbe69b4de8a6f0048ff9389a1313c931908d2a3393e06afb7fda5ebc6a85cfa
|
File details
Details for the file pycrypt_jasypt-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pycrypt_jasypt-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1736d8a8d4688f8569f7d9742e459e6a22fd77d219b23d119fd6d1cd8b0e2e77
|
|
| MD5 |
174b20c1b5d85a8ac5e6cc674decab32
|
|
| BLAKE2b-256 |
327d6f9fe5982f031d0387f9b9a55528508da958b47e8910e1f3661669ccea68
|