Aes

object Aes

Pure-Kotlin AES (FIPS 197), modes ECB-decrypt + CBC-decrypt for PDF V4/V5 Standard Security Handlers. Supports 128-bit and 256-bit keys.

PDF V4 encrypts streams with AES-128-CBC using an IV prepended to the ciphertext (first 16 bytes). PDF V5/V6 uses AES-256-CBC the same way.

Not for general use. This is a textbook implementation — no side-channel hardening, no timing-attack resistance, no AES-NI. It's here because PDF needs decryption to open the document; the underlying threat model is "rightful owner who has the password," not "attacker with timing."

Functions

Link copied to clipboard
fun decryptCbc(key: ByteArray, ciphertext: ByteArray, removePadding: Boolean = true): ByteArray

Decrypt CBC-mode ciphertext. The first 16 bytes are the IV.

Link copied to clipboard

Decrypt one ECB block (used for the key-string encryption in V4).

Link copied to clipboard
fun encryptCbc(key: ByteArray, iv: ByteArray, plaintext: ByteArray): ByteArray

Encrypt CBC-mode plaintext, prepending the IV. PKCS#7 padding.