gchq/CyberChef · error · OperationError
KEK must be either 16, 24, or 32 bytes (currently " + kek.le
Error message
KEK must be either 16, 24, or 32 bytes (currently " + kek.length + " bytes)
What it means
AESKeyWrap (RFC 3394) uses an AES Key-Encryption-Key whose size must be a valid AES key size: 16, 24, or 32 bytes. This is the same constraint enforced by the unwrap operation, validated before any wrap work.
Source
Thrown at src/core/operations/AESKeyWrap.mjs:68
"type": "option",
"value": ["Hex", "Raw"]
},
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const kek = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
inputType = args[2],
outputType = args[3];
if (kek.length !== 16 && kek.length !== 24 && kek.length !== 32) {
throw new OperationError("KEK must be either 16, 24, or 32 bytes (currently " + kek.length + " bytes)");
}
if (iv.length !== 8) {
throw new OperationError("IV must be 8 bytes (currently " + iv.length + " bytes)");
}
const inputData = Utils.convertToByteString(input, inputType);
if (inputData.length % 8 !== 0 || inputData.length < 16) {
throw new OperationError("input must be 8n (n>=2) bytes (currently " + inputData.length + " bytes)");
}
const cipher = forge.cipher.createCipher("AES-ECB", kek);
let A = iv;
const R = [];
for (let i = 0; i < inputData.length; i += 8) {
R.push(inputData.substring(i, i + 8));
}
let cntLower = 1, cntUpper = 0;
for (let j = 0; j < 6; j++) {View on GitHub (pinned to 4290ea7539)
Solutions
- Set the KEK format option to match its representation (Hex/Base64/UTF8).
- Confirm the KEK is exactly 16, 24, or 32 bytes.
- Derive the KEK through a KDF that pins the output length.
Example fix
// before: 16-char KEK with format Hex → 8 bytes → throws // after: set KEK format to "UTF8" (raw 16 bytes)
Defensive patterns
Strategy: validation
Validate before calling
function validateKek(kekBytes) {
if (![16, 24, 32].includes(kekBytes.length)) {
throw new Error(`KEK must be 16/24/32 bytes, got ${kekBytes.length}`);
}
} Type guard
function isAesKek(bytes) { return bytes instanceof Uint8Array && [16, 24, 32].includes(bytes.length); } Try / catch
try { aesKeyWrap(...); } catch (e) { if (/KEK must be/.test(e.message)) {/* fix KEK format */} else throw e; } Prevention
- Match the KEK format option to its representation.
- Pin KDF output to a valid AES key length.
- Assert KEK length before wrapping.
When it happens
Trigger: args[0] (KEK) converted to a byte string yields a length outside {16, 24, 32}. Typically a Key Format option mismatch on the KEK field.
Common situations: KEK supplied as hex with format UTF8 (or vice versa); short passphrase used directly as KEK; KEK from another system whose length does not match a valid AES key size.
Related errors
- KEK must be either 16, 24, or 32 bytes (currently " + kek.le
- IV must be 8 bytes (currently " + iv.length + " bytes)
- input must be 8n (n>=3) bytes (currently " + inputData.lengt
- IV must be 8 bytes (currently " + iv.length + " bytes)
- input must be 8n (n>=2) bytes (currently " + inputData.lengt
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/2e94bd825dd54f43.
Report an issue: GitHub.