pip install einarfrom einar import AES
key = b'' # The key can be any size; it will be padded or truncated to the required length.
# AES-256 CBC example
iv = b'1234567890abcdef' # Required for CBC mode, must be 16 bytes
cipher = AES(key, keyLen=256, mode="CBC", iv=iv)
message = b'Secret message to encrypt'ciphertext = cipher.encrypt(message)
print(f"Ciphertext (hex): {ciphertext.hex()}")original_text = cipher.decrypt(ciphertext)
print(f"Original text: {original_text.decode('utf-8')}")cipher = AES(key, keyLen=128, mode="ECB")
ciphertext = cipher.encrypt(message)
original_text = cipher.decrypt(ciphertext)iv = b'1234567890abcdef' # 16 bytes
cipher = AES(key, keyLen=256, mode="CBC", iv=iv)
ciphertext = cipher.encrypt(message)
original_text = cipher.decrypt(ciphertext)Einar includes a command-line interface for encryption and decryption:
einar -e "Secret message" -kl 256 -m CBCDistributed under GPL v2 or later.
Juan