PyAES provides a pure-Python implementation of the Advanced Encryption Standard (AES) block cipher, along with common modes of operation like CBC, CTR, and OFB. Currently at version 1.6.1, it offers a lightweight cryptographic option for environments where C extensions are not feasible or desired. Its release cadence is low, with updates typically addressing bug fixes or minor enhancements.
pip install pyaesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates encrypting and decrypting data using AES in CBC mode with a 256-bit key. It highlights the use of `AESModeOfOperationCBC` and the necessity of providing a unique IV for each encryption operation. PyAES uses zero-padding by default if the plaintext length is not a multiple of the block size.
Ensure `key` is 16, 24, or 32 bytes long, and `iv` (for CBC/CTR/OFB) is 16 bytes long. Use `os.urandom()` for cryptographically secure random values.
Ensure you are using version 1.6.0 or higher for reliable stream API functionality. Review code that interacted with the stream API in 1.5.0 as workarounds may no longer be necessary or compatible.
For robust applications, implement a cryptographically secure padding scheme like PKCS7 or ISO 10126 before encryption and unpadding after decryption, rather than relying on `pyaes`'s default zero-padding.
Always generate a new, cryptographically random IV (e.g., `os.urandom(16)`) for every distinct encryption operation with the same key in CBC mode. Store and transmit the IV alongside the ciphertext (it does not need to be secret).
Install the library using pip: `pip install pyaes`
Ensure the key is exactly 16, 24, or 32 bytes long. Example: `key = b'This is a 16-byte key'`
Utilize `pyaes.Encrypter` and `pyaes.Decrypter` with `feed` and `feed_final` methods to handle plaintext of any length, as these classes include automatic padding. Example: `encrypter = pyaes.Encrypter(aes_mode); ciphertext = encrypter.feed(plaintext); ciphertext += encrypter.feed_final()`
Encode your string data to bytes before passing it to `pyaes` functions. Example: `plaintext.encode('utf-8')` or `key_string.encode('utf-8')`No dependency data recorded yet.