aesio – AES encryption routines

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

Available on these boards
  • ARAMCON Badge 2019
  • ARAMCON2 Badge
  • Adafruit CLUE nRF52840 Express
  • Adafruit Circuit Playground Bluefruit
  • Adafruit Feather Bluefruit Sense
  • Adafruit Feather nRF52840 Express
  • Adafruit ItsyBitsy nRF52840 Express
  • Adafruit Metro nRF52840 Express
  • Arduino Nano 33 BLE
  • AtelierDuMaker nRF52840 Breakout
  • BLE-SS dev board Multi Sensor
  • BastBLE
  • Electronut Labs Blip
  • Electronut Labs Papyr
  • HiiBot BlueFi
  • IkigaiSense Vita nRF52840
  • MDBT50Q-DB-40
  • MakerDiary nRF52840 MDK
  • MakerDiary nRF52840 MDK USB Dongle
  • Makerdiary M60 Keyboard
  • Makerdiary Pitaya Go
  • Makerdiary nRF52840 M.2 Developer Kit
  • Open Hardware Summit 2020 Badge
  • PCA10056 nRF52840-DK
  • PCA10059 nRF52840 Dongle
  • Particle Argon
  • Particle Boron
  • Particle Xenon
  • Simmel
  • SparkFun MicroMod nRF52840
  • SparkFun Pro nRF52840 Mini
  • TG-Watch
  • Teknikio Bluebird
  • TinkeringTech ScoutMakes Azul
  • nice!nano

class aesio.AES(key: _typing.ReadableBuffer, mode: int = 0, iv: Optional[_typing.ReadableBuffer] = None, segment_size: int = 8)

Encrypt and decrypt AES streams

Create a new AES state with the given key.

Parameters
  • key (ReadableBuffer) – A 16-, 24-, or 32-byte key

  • mode (int) – AES mode to use. One of: AES.MODE_ECB, AES.MODE_CBC, or AES.MODE_CTR

  • iv (ReadableBuffer) – Initialization vector to use for CBC or CTR mode

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.MODE_ECB)
cipher.encrypt_into(inp, outp)
hexlify(outp)
encrypt_into(self, src: _typing.ReadableBuffer, dest: _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. For CTX mode, there are no restrictions.

decrypt_into(self, src: _typing.ReadableBuffer, dest: _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 CTX mode, there are no restrictions.