← Cryptography guide

K026 / Cipher modes and AEAD

AES-CBC

CBC cipher block chaining mode · Survey date 2026-12-05

CBC encrypts fixed-length blocks by XORing each plaintext block with the preceding ciphertext block before encryption.

CRYPTOGRAPHY LAB / K026

Cryptography Lab · AES-CBC

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Limited implementation

AES-CBC (raw, no padding)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

Definition and overview
CBC encrypts fixed-length blocks by XORing each plaintext block with the preceding ciphertext block before encryption. Source document ↗
Classification and reversibility
Reversible symmetric block-cipher mode with defined decryption. Source document ↗
Key or secret requirements
Requires a symmetric key. Source document ↗
Operating principle and structure
XOR first plaintext block with IV, subsequent blocks with preceding ciphertext, then encrypt each. Source document ↗
Key size, block size and parameters
AES-CBC requires a 16-octet IV and block-aligned padding. Source document ↗
Security strength and recommendation
Valid for some uses such as static content; TLS MAC-then-encrypt CBC is problematic and not recommended. Source document ↗
Known attacks and vulnerabilities
Known attacks include BEAST exploiting predictable TLS 1.0 IVs and padding oracles/Lucky Thirteen. Source document ↗
Standards and certification
NIST SP 800-38A defines confidentiality modes including CBC. Source document ↗
Typical uses
Historically widespread in SSL/TLS cipher suites. Source document ↗
Implementations, libraries and tools
PyCryptodome Crypto.Cipher provides CBC objects. Source document ↗
Decryption or decoding
Decrypt each block, then XOR with preceding ciphertext (IV for first block). Source document ↗
Advantages
Chaining makes each ciphertext depend on all preceding plaintext blocks, reducing exposure of repeated patterns. Source document ↗
Limitations and cautions
CBC does not authenticate ciphertext integrity; susceptible to tampering, so AEAD is recommended. Source document ↗
Distinguishing encryption, encoding and hashing
CBC provides confidentiality only, distinct from Base64, hashing and AEAD. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Split plaintext into AES blocks, XOR the first with IV and encrypt, then XOR each following block with previous ciphertext before encryption. Decrypt using key and IV and remove padding.

Procedure

Prepare key and fresh IV per message, pad plaintext, encrypt first block after XOR with IV, remaining after XOR with previous ciphertext, store/send IV and ciphertext. Decrypt each block and XOR with previous ciphertext or IV, verify/remove padding. Base64 is separate keyless encoding.

Scenario

For legacy TLS or stored CBC data, confirm key, IV, padding rules and integrity protection. Prefer AEAD for new designs; if CBC is unavoidable for static content, add authentication/tamper verification.

Pitfalls and alternatives

Avoid reused/predictable IVs, padding oracles and MAC-then-encrypt; migrate to AES-GCM/ChaCha20-Poly1305. Distinguish encoding/hash and provide separate CBC integrity protection.

Diagram source ↗

References