PKCS#7 padding
PKCS#7 padding is a byte-padding scheme in which each appended byte contains the number of padding bytes added to complete a block.
Hacking Cryptography
PKCS#7 padding is a byte-padding scheme in which each padding byte contains the number of padding bytes added to complete a block.
- How it is used
- Fits plaintext to block-cipher boundaries before encryption and supports unpadding after decryption.
- How deep it goes
- Defines the byte rule, exact-block behavior, construction, removal, validation, and padding-oracle consequence.
- Examples
- Uses repeated 0x04 bytes, Go padding functions, and an AES-CBC encrypted-timestamp server.
- What you can do after
- Build it from scratch with padding, removal, and validation routines while avoiding distinguishable padding errors.
Real-World Cryptography
PKCS#7 padding appends bytes whose values equal the number of padding bytes required to reach a block boundary.
- How it is used
- Prepares plaintext for block encryption by extending it to a complete block boundary.
- How deep it goes
- Explains the padding rule, full-block case, reversibility, and unpadding procedure, but not implementation details.
- Examples
- Uses eight-byte plaintext padded with eight bytes of value 8, plus a full sixteen-byte padding block.
- What you can do after
- Apply it when preparing and reversing block-cipher plaintext, including messages already aligned to a block.
Related concepts
- paddingkind of · Padding is the addition of extra space, values, or data around or within a structure to satisfy size, alignment, layout, or processing requirements.
- AESused by · AES is a standardized symmetric block cipher that encrypts and decrypts data in 128-bit blocks using 128-, 192-, or 256-bit keys.
- encryptionconfigures · Encryption is the cryptographic transformation of readable data into ciphertext to conceal its contents, reversible through decryption with appropriate information.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

