Data Alignment & Security
Padding Scheme Explorer
Cryptographic algorithms often require inputs to be a specific length, or require randomness to prevent deterministic patterns. Padding schemes solve these problems. Explore how symmetric ciphers pad data to fit block sizes, and how asymmetric ciphers use padding to ensure IND-CCA2 security and prevent forgery.
Padding Scheme Comparison
PKCS#7Symmetric
To pad messages to a multiple of the block size for block ciphers.
| Used In | AES (CBC, ECB), DES |
|---|---|
| Compatibility | Encryption only |
| Security | Deterministic. Vulnerable to padding oracle attacks (e.g., POODLE) if used in CBC mode without proper MAC-then-Encrypt or Encrypt-then-MAC authentication. |
How it is generated
Appends N bytes of value N. If the message is already a multiple of the block size, a full block of padding is added (e.g., 16 bytes of 0x10).
Use Cases
Legacy APIs, older TLS versions, basic symmetric encryption.
Limitations
Does not provide integrity. Should be avoided in modern designs in favor of authenticated encryption modes like GCM, which do not require padding.
Visual Structure
10 bytes of padding added to reach a multiple of the 16-byte block size.