gchq/CyberChef · error · OperationError
Unknown padding type: ${padding}
Error message
Unknown padding type: ${padding} What it means
Default branch of applyPadding's switch in TEA.mjs:214. Any padding value other than {NO, PKCS5, ZERO, RANDOM, BIT} reaches this throw, reporting the unrecognised value.
Source
Thrown at src/core/lib/TEA.mjs:213
case "NO":
throw new OperationError(
`No padding requested but input length (${message.length} bytes) is not a multiple of ${BLOCK_SIZE} bytes.`
);
case "PKCS5":
for (let i = 0; i < nPadding; i++) padded.push(nPadding);
break;
case "ZERO":
for (let i = 0; i < nPadding; i++) padded.push(0);
break;
case "RANDOM":
for (let i = 0; i < nPadding; i++) padded.push(Math.floor(Math.random() * 256));
break;
case "BIT":
padded.push(0x80);
for (let i = 1; i < nPadding; i++) padded.push(0);
break;
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
return padded;
}
/**
* Remove padding from message
* @param {number[]} message
* @param {string} padding
* @returns {number[]}
*/
function removePadding(message, padding) {
if (message.length === 0) return message;
switch (padding) {
case "NO":
case "ZERO":
case "RANDOM":View on GitHub (pinned to 4290ea7539)
Solutions
- Pass one of: 'NO', 'PKCS5', 'ZERO', 'RANDOM', 'BIT'.
- Normalise (trim + uppercase) and validate against an allowlist before encrypting.
- For PKCS#7-style padding use the literal 'PKCS5'.
Example fix
// before encryptWithBlockMode(msg, key, iv, "CBC", "PKCS7"); // after encryptWithBlockMode(msg, key, iv, "CBC", "PKCS5");
Defensive patterns
Strategy: validation
Validate before calling
const TEA_PADDING = new Set(["NO", "PKCS5", "ZERO", "RANDOM", "BIT"]);
function normaliseTeaPadding(p) {
const v = String(p).trim().toUpperCase();
if (!TEA_PADDING.has(v)) throw new TypeError(`Unsupported TEA padding: ${JSON.stringify(p)}`);
return v;
} Type guard
function isTeaPadding(v) {
return typeof v === "string" &&
["NO","PKCS5","ZERO","RANDOM","BIT"].includes(v.trim().toUpperCase());
} Try / catch
try {
encryptWithBlockMode(msg, key, iv, mode, normaliseTeaPadding(padding));
} catch (e) {
if (e instanceof TypeError && /Unsupported TEA padding/.test(e.message)) {
// report unsupported padding
} else throw e;
} Prevention
- Normalise padding literals (trim + uppercase) at the trust boundary.
- Use the literal 'PKCS5' for PKCS#7-style padding (the library does not accept 'PKCS7').
- Share one padding allowlist across encrypt and decrypt.
When it happens
Trigger: Encrypt path called with padding not in the supported set. Examples: 'PKCS7' (not a recognised literal here — use 'PKCS5'), 'ANSIX923', lowercase 'pkcs5', an empty string, or undefined.
Common situations: Padding string sourced from user input or a recipe without normalisation; downstream code uses a different enum name than the library; refactor renamed the enum on one side only.
Related errors
- No padding requested but input length (${message.length} byt
- Invalid PKCS#5 padding.
- Invalid BIT padding.
- Invalid block cipher mode: ${mode}
- Invalid block cipher mode: ${mode}
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/abda595b1e5d1bc9.
Report an issue: GitHub.