gchq/CyberChef · error · OperationError
Unknown padding type: ${padding}
Error message
Unknown padding type: ${padding} What it means
Thrown by RC6.applyPadding when the `padding` argument matches none of the handled cases ('NO','PKCS5','ZERO','RANDOM','BIT'). Indicates a typo, an unsupported scheme, or an undefined value.
Source
Thrown at src/core/lib/RC6.mjs:386
paddedMessage.push(0);
}
break;
case "RANDOM":
for (let i = 0; i < nPadding; i++) {
paddedMessage.push(Math.floor(Math.random() * 256));
}
break;
case "BIT":
paddedMessage.push(0x80);
for (let i = 1; i < nPadding; i++) {
paddedMessage.push(0);
}
break;
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
return paddedMessage;
}
/**
* Remove padding from message
* @param {number[]} message - Padded message
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @param {number} blockSize - Block size in bytes
* @returns {number[]} - Unpadded message
*/
function removePadding(message, padding, blockSize) {
if (message.length === 0) return message;
switch (padding) {
case "NO":
case "ZERO":View on GitHub (pinned to 4290ea7539)
Solutions
- Use one of the supported values exactly: 'NO','PKCS5','ZERO','RANDOM','BIT'.
- If you need PKCS7, note that for RC6's 16-byte block PKCS5 and PKCS7 are equivalent — use 'PKCS5'.
- Validate the padding value against the allowed list before calling.
Example fix
// before encryptRC6(msg, key, iv, 'CBC', 'PKCS7'); // after encryptRC6(msg, key, iv, 'CBC', 'PKCS5');
Defensive patterns
Strategy: validation
Validate before calling
const RC6_PADDINGS = new Set(['NO','PKCS5','ZERO','RANDOM','BIT']);
if (!RC6_PADDINGS.has(padding)) {
throw new Error(`Unknown RC6 padding '${padding}'`);
} Type guard
function isRc6Padding(p) {
return ['NO','PKCS5','ZERO','RANDOM','BIT'].includes(p);
} Try / catch
try {
return encryptRC6(message, key, iv, mode, padding, rounds, w);
} catch (e) {
if (e instanceof OperationError && /Unknown padding type/.test(e.message)) {
return encryptRC6(message, key, iv, mode, 'PKCS5', rounds, w);
}
throw e;
} Prevention
- Whitelist the padding value at the call site.
- Remember PKCS5 and PKCS7 are equivalent at RC6's 16-byte block — use 'PKCS5'.
- Map padding names from other libraries to this set explicitly.
When it happens
Trigger: Calling encryptRC6/decryptRC6 with a padding string outside the supported set, e.g. 'PKCS7', 'ISO10126', 'ANSIX923', '', or undefined (the default parameter is 'PKCS5' but an explicit undefined passed positionally overrides nothing — explicit bad strings do hit it).
Common situations: Confusing PKCS5 with PKCS7; passing a padding name from a different library; UI dropdown value renamed; forgotten argument shifting positions.
Related errors
- No padding requested but input is not a ${blockSize}-byte mu
- Invalid PKCS#5 padding.
- Invalid BIT padding.
- Letter ${letter} is not included in LS47
- No padding requested but input is not a ${blockSize}-byte mu
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/091d0bddc03324a2.
Report an issue: GitHub.