Skip to content

jc-lab/asn1cipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asn1cipher

A Python library for encrypting and decrypting ASN.1 encrypted content. Uses asn1crypto library's EncryptionAlgorithm and EncryptedContentInfo.

Features

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)

Quick Start

Basic Usage

examples/basic_usage.py

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!")

License

Apache-2.0 License

Contributing

Contributions are welcome! Please submit a Pull Request.

Related Projects

Author

joseph@jc-lab.net

About

cipher utils for asn1crypto

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages