AES-PKCS5 Encryption Library

1.0.4 · active · verified Fri Apr 17

aes-pkcs5 is a Python library providing an implementation of the Advanced Encryption Standard (AES) using CBC and ECB modes, specifically incorporating the PKCS5 padding scheme. It is currently at version 1.0.4 and maintains an active release cadence, with recent updates focusing on Python version compatibility and modernization.

Common errors

Warnings

Install

Imports

Quickstart

Initializes an AESCipher with a key and IV, then demonstrates encrypting and decrypting a simple string. The library handles base64 encoding/decoding of the encrypted output automatically.

from aes_pkcs5.algorithms import AESCipher

# Note: Key and IV should be securely generated and managed in production.
# For AES-128, key/IV length must be 16 bytes. For AES-256, 32 bytes.
# The library expects string input for key/IV by default, but bytes are also supported from v1.0.3+
key = 'This is a key123'
iv = 'This is an IV456'

cipher = AESCipher(key, iv)

data_to_encrypt = 'Hello, secure world!'

# Encrypt
encrypted_text = cipher.encrypt(data_to_encrypt)
print(f"Original: {data_to_encrypt}")
print(f"Encrypted (base64 encoded): {encrypted_text}")

# Decrypt
decrypted_text = cipher.decrypt(encrypted_text)
print(f"Decrypted: {decrypted_text}")

view raw JSON →