Skip to content
uencoder

Padding

Padding is the mechanism that extends the plaintext to a block boundary; common schemes include PKCS#7, zero padding, and ISO 10126, while AEAD modes need none.

Purpose

It lets block ciphers process plaintexts whose length is not a multiple of the block size.

Mechanism

Bytes are appended to the plaintext so the total length becomes a multiple of the block size, and are stripped on decryption. PKCS#7 appends n bytes each of value n (reversible and self-verifying). Zero padding is simple but cannot distinguish padding from data. Stream modes (CTR) and AEAD (GCM) need no padding.

Use cases

  • AES-CBC/PKCS#7 padding
  • RSA OAEP padding
  • Legacy zero-padding schemes
  • Teaching examples

Examples

  • Input
    3 bytes + PKCS#7 (block=8)
    Output
    appends 05 05 05 05 05

    Pads with five 0x05 bytes

Common errors

Zero padding cannot distinguish trailing data zeros from padding
Use a self-describing scheme such as PKCS#7
Padding errors fall to Padding Oracle attacks
Use AEAD or constant-time validation

Related terms

Related tools

References