A Python library for encrypting and decrypting ASN.1 encrypted content. Uses asn1crypto library's EncryptionAlgorithm and EncryptedContentInfo.
Algorithm Oid
- PBES1 support (
1.2.840.113549.1.5.X) - PKCS#12 encryption support (
1.2.840.113549.1.12.1.X) - PBES2/PBKDF2 support (
1.2.840.113549.1.5.13)
Cipher Algorithm
- RC2 block cipher
- Custom Block Cipher Support (BlockCipher abstraction)
from asn1cipher import Provider
from asn1crypto.algos import EncryptionAlgorithm, Pbes1Params
from asn1crypto.core import OctetString
import os
# Create Provider instance
provider = Provider()
# Data to encrypt and password
plaintext = b"Hello, World! This is a secret message."
password = b"my_secret_password"
# Configure PBES1 (SHA1 + DES) algorithm
encryption_algorithm = EncryptionAlgorithm({
'algorithm': 'pbes1_sha1_des',
'parameters': Pbes1Params({
'salt': os.urandom(8),
'iterations': 10000,
})
})
# Encrypt
encrypted_content_info = provider.encrypt(
plaintext=plaintext,
password=password,
encryption_algorithm=encryption_algorithm
)
# Decrypt
decrypted = provider.decrypt(
encrypted_content_info=encrypted_content_info,
password=password
)
assert decrypted == plaintext
print("✓ Encryption/decryption successful!")Apache-2.0 License
Contributions are welcome! Please submit a Pull Request.
- asn1crypto - ASN.1 parsing and serialization
- cryptography - Python cryptography library