aesio – AES encryption routines — Adafruit CircuitPython 1 documentation (original) (raw)

Adafruit CircuitPython

The AES module contains classes used to implement encryption and decryption. It aims to be low overhead in terms of memory.

For more information on AES, refer to the Wikipedia entry.

Available on these boards

aesio.MODE_ECB_: int_

aesio.MODE_CBC_: int_

aesio.MODE_CTR_: int_

class aesio.AES(key: circuitpython_typing.ReadableBuffer, mode: int = 0, IV: circuitpython_typing.ReadableBuffer | None = None, segment_size: int = 8)

Encrypt and decrypt AES streams

Create a new AES state with the given key.

Parameters:

Additional arguments are supported for legacy reasons.

Encrypting a string:

import aesio from binascii import hexlify

key = b'Sixteen byte key' inp = b'CircuitPython!!!' # Note: 16-bytes long outp = bytearray(len(inp)) cipher = aesio.AES(key, aesio.MODE_ECB) cipher.encrypt_into(inp, outp) hexlify(outp)

rekey(key: circuitpython_typing.ReadableBuffer, IV: circuitpython_typing.ReadableBuffer | None = None) → None

Update the AES state with the given key.

Parameters:

encrypt_into(src: circuitpython_typing.ReadableBuffer, dest: circuitpython_typing.WriteableBuffer) → None

Encrypt the buffer from src into dest.

For ECB mode, the buffers must be 16 bytes long. For CBC mode, the buffers must be a multiple of 16 bytes, and must be equal length. Any included padding must conform to the required padding style for the given mode. For CTR mode, there are no restrictions.

decrypt_into(src: circuitpython_typing.ReadableBuffer, dest: circuitpython_typing.WriteableBuffer) → None

Decrypt the buffer from src into dest. For ECB mode, the buffers must be 16 bytes long. For CBC mode, the buffers must be a multiple of 16 bytes, and must be equal length. For CTR mode, there are no restrictions.