NodeCrypto Help

Padding Standards

Block ciphers in ECB and CBC modes operate only on whole blocks (16 bytes for AES/SEED/ARIA/Camellia/SM4, 8 bytes for DES/TDES). When the plaintext length is not an exact multiple of the block size—or when the padding scheme requires unambiguous removal—padding bytes are appended to reach a block boundary. In NodeCrypto, symmetric Encrypt/Decrypt nodes and the standalone Block Padding and Block Unpadding nodes share the same padding standard names.

Block 1 (16 Bytes) Tail Data (10B) + Pad (6B) Block Cipher (ECB / CBC) Exact 16B Block Boundary Unaligned trailing bytes are padded to complete the final cipher block
StandardBlock SizeWhen Input Is Already Block-AlignedUnpad (Reversible)
NoneInput length must already be a multiple of the block sizeUsed as-is (throws an error if unaligned)Supported (no-op)
ISO 9797-1 M1Any block sizeAdds nothing (0 bytes added)Not supported
ISO 9797-1 M2Any block sizeAppends a full padding block (80 00 … 00)Supported
ISO 9797-1 M3Any block size (length block uses the same byte width as the block size)Prepends a full length block and applies Method 1Supported
PKCS#5/7PKCS#5 is defined for 8-byte (DES) blocks; PKCS#7 generalizes the identical algorithm to 1–255 byte blocksAppends a full padding blockSupported
NIST 800-38BAny block sizeAdds nothing (0 bytes added)Not supported
ANSI X9.23Any block size (1–255 bytes)Appends a full padding blockSupported

Padding methods that do not support unpadding (Zero and NIST80038B) cannot distinguish trailing data bytes from padding bytes when the original input was already block-aligned. Consequently, they are omitted from symmetric Decrypt nodes and the Block Unpadding node.

None (No Padding)

Standard: —
Block Size: Input length must already be a multiple of the block size
Unpad (Reversible): Supported

Applies no padding bytes. In block modes (ECB and CBC), if the input length is not an exact multiple of the cipher's block size, execution fails with PLAINTEXT_NOT_BLOCK_ALIGNED (or CIPHERTEXT_NOT_BLOCK_ALIGNED). Use None when your data is already block-aligned, when using stream/AEAD modes (CTR, GCM, CCM, CFB, OFB), or when you apply padding manually with an upstream Block Padding node.

16-byte block (already aligned) — Original 16B → Padded 16B
4142434445464748494a4b4c4d4e4f50
Original Data

ISO/IEC 9797-1 Method 1 (Zero Padding)

Standard: ISO/IEC 9797-1:2011, Padding Method 1
Block Size: Any block size
Unpad (Reversible): Not supported (One-Way)

Appends 0x00 bytes to the end of the data until it reaches a block boundary. If the input length is already a multiple of the block size (and non-empty), no bytes are added.

Designed for MAC calculation (such as retail CBC-MAC). Because it cannot distinguish original data ending in 0x00 from padding bytes, it is fundamentally non-reversible and is not offered in Decrypt or Block Unpadding nodes.
16-byte block (unaligned → zero bytes appended) — Original 10B → Padded 16B
4142434445464748494a000000000000
Original DataPadding Bytes
16-byte block (already aligned → no-op) — Original 16B → Padded 16B
4142434445464748494a4b4c4d4e4f50
Original Data

ISO/IEC 9797-1 Method 2 (ISO/IEC 7816-4)

Standard: ISO/IEC 9797-1:2011 Method 2 / ISO/IEC 7816-4 (Smart Card APDU Padding)
Block Size: Any block size
Unpad (Reversible): Supported

Appends a mandatory 0x80 delimiter byte (a single 1 bit followed by seven 0 bits) and then fills the remainder of the block with 0x00 bytes. Even when the input is already block-aligned, a full new block starting with 0x80 is appended, making unpadding completely unambiguous by scanning backward for the last 0x80 byte.

16-byte block — Original 10B → Padded 16B
4142434445464748494a800000000000
Original DataPadding Bytes

ISO/IEC 9797-1 Method 3

Standard: ISO/IEC 9797-1:2011, Padding Method 3
Block Size: Any block size (length block equals the block size)
Unpad (Reversible): Supported

Prepends a full block containing the original message bit length encoded as a big-endian unsigned integer, and then pads the trailing message block with 0x00 bytes (Method 1). During unpadding, the leading length block is read to recover the exact byte length of the original message.

Originally defined for MAC algorithms (ISO/IEC 9797-1 MAC Algorithm 3 / ANSI X9.19). Note that the padded output is always at least one full block longer than the input due to the prepended length block.
16-byte block — Original 10B (80 bits = 0x50, stored by byte/bit convention) → Padded 32B
0000000000000000000000000000000a4142434445464748494a000000000000
Length BlockOriginal DataPadding Bytes

PKCS#5 (8-Byte Block) / PKCS#7 (Arbitrary Block)

Standard: PKCS#5 v1.5 (8-byte DES blocks) / PKCS#7 — RFC 5652 §6.3 (CMS)
Block Size: 1–255 bytes
Unpad (Reversible): Supported

Appends N padding bytes (where 1 ≤ N ≤ blockSize), with every added byte set to the value N. If the input length is already a multiple of the block size, a full block of blockSize bytes (each equal to blockSize, e.g. sixteen 0x10 bytes for AES) is appended. During unpadding, the last byte specifies how many trailing bytes to strip and verify.

16-byte block (AES/SEED/ARIA/Camellia/SM4, PKCS#7) — Original 10B → Padded 16B
4142434445464748494a060606060606
Original DataPadding Bytes
8-byte block (DES/TDES, PKCS#5) — Original 5B → Padded 8B
4142434445030303
Original DataPadding Bytes

NIST SP 800-38B

Standard: NIST Special Publication 800-38B (CMAC Authentication Mode)
Block Size: Any block size
Unpad (Reversible): Not supported (One-Way)

Padding function defined for CMAC block preparation. Like ISO/IEC 9797-1 Method 2, it appends 0x80 followed by 0x00 bytes when the data is not block-aligned. Unlike Method 2, if the data is already a non-empty multiple of the block size, it appends nothing.

Because aligned inputs are left untouched, an aligned plaintext ending in 80 00 … cannot be distinguished from a padded shorter plaintext. Therefore, NIST SP 800-38B padding cannot be unpadded and is available only for encryption/padding.
16-byte block (unaligned → 0x80 + 0x00 appended) — Original 10B → Padded 16B
4142434445464748494a800000000000
Original DataPadding Bytes
16-byte block (already aligned → no-op, unlike ISO 9797-1 M2) — Original 16B → Padded 16B
4142434445464748494a4b4c4d4e4f50
Original Data

ANSI X9.23

Standard: ANSI X9.23 (Financial Institution Message Encryption)
Block Size: 1–255 bytes
Unpad (Reversible): Supported

Fills all padding bytes except the final byte with 0x00, and writes the padding length N (1 ≤ N ≤ blockSize) into the very last byte. Like PKCS#7, it always appends a full padding block when the input is already block-aligned.

16-byte block — Original 10B → Padded 16B
4142434445464748494a000000000006
Original DataPadding Bytes