Skip to Content
oxcrypto

Hazmat

Raw block operations and ECB.

from oxcrypto.cipher.aes import AES
from oxcrypto.cipher.hazmat import ECB, decrypt_block, encrypt_block

key = bytes.fromhex("000102030405060708090a0b0c0d0e0f")
block = bytes.fromhex("00112233445566778899aabbccddeeff")
assert encrypt_block(key, block, cipher=AES.AES128).hex() == "69c4e0d86a7b0430d8cdb78070b4c55a"
assert ECB.ECB.encrypt(key, block, cipher=AES.AES128)[:16] == encrypt_block(key, block, cipher=AES.AES128)

Warning

These functions encrypt one block or every block independently. Equal plaintext blocks give equal ciphertext blocks. Use them only to build or interoperate with a protocol.

encrypt_block and decrypt_block take exactly one block. ECB.ECB takes the same padding= options as CBC and has encryptor and decryptor contexts.