Skip to content

AES API Reference

Auto-generated API documentation for the AES encryption module.

aes -- AES Encryption (OpenSSL + Pure Python)

aes

AES encryption: ECB, CBC, CTR, and GCM modes for 128/192/256-bit keys.

Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.

At import time this module tries to load the system libcrypto via ctypes for native-C performance. If the library is unavailable the pure-Python implementation is used instead. The public API is identical regardless of which backend is active.

Check :data:BACKEND to see which one was selected at runtime::

>>> from aes.aes import BACKEND
>>> print(BACKEND)        # "openssl" or "python"

Pure-Python AES based on bozhu/AES-Python (MIT License): Copyright (C) 2012 Bo Zhu http://about.bozhu.me https://github.com/bozhu/AES-Python

aes_ecb_padded_size(plaintext_size)

Calculate the ciphertext size after AES-ECB + PKCS7 padding.

Parameters:

Name Type Description Default
plaintext_size int

Size of the original data in bytes.

required

Returns:

Type Description
int

Size of the encrypted output in bytes.

Source code in aes/aes.py
def aes_ecb_padded_size(plaintext_size: int) -> int:
    """Calculate the ciphertext size after AES-ECB + PKCS7 padding.

    Args:
        plaintext_size: Size of the original data in bytes.

    Returns:
        Size of the encrypted output in bytes.
    """
    pad_len = 16 - (plaintext_size % 16)
    return plaintext_size + pad_len