gchq/CyberChef · error · OperationError
Invalid key length: ${key.length} bytes XTEA requires a key
Error message
Invalid key length: ${key.length} bytes
XTEA requires a key length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8). What it means
Thrown by XTEADecrypt.run when the converted key byte array is not exactly 16 bytes. XTEA uses a fixed 128-bit key; the check is a strict length-16 test before IV and rounds are validated.
Source
Thrown at src/core/operations/XTEADecrypt.mjs:84
"value": 32,
"min": 1,
"max": 255
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding, rounds] = args;
if (key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
XTEA requires a key length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
XTEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)
throw new OperationError(`Invalid number of rounds: ${rounds}
Rounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.`);
// Default IV to null bytes if empty (like AES)
const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;
View on GitHub (pinned to 4290ea7539)
Solutions
- Ensure the decoded key is exactly 16 bytes (32 hex chars, 16 UTF8 bytes).
- Match the 'Key format' option to the actual key encoding.
- Regenerate a 128-bit key in the correct format.
Example fix
// before: 16 hex chars -> 8 bytes
args:[{string:"0123456789abcdef",option:"Hex"}, ...]
// after: 32 hex chars -> 16 bytes
args:[{string:"0123456789abcdef0123456789abcdef",option:"Hex"}, ...] Defensive patterns
Strategy: validation
Validate before calling
function xteaKeyRecipe(keyStr, keyOption) {
const key = Utils.convertToByteArray(keyStr, keyOption);
if (key.length !== 16) throw new Error(`XTEA key must be 16 bytes, got ${key.length}`);
return {string:keyStr, option:keyOption};
} Type guard
const isXteaKeyLen = (bytes) => bytes.length === 16;
Try / catch
try { chef.bake(data, recipe); } catch (e) { if (/key length/.test(e.message) && /XTEA/.test(e.message)) { /* fix key */ } else throw e; } Prevention
- Decode and assert 16-byte keys before baking.
- Keep key format option consistent.
- Derive keys via a KDF rather than padding short passphrases.
When it happens
Trigger: args[0].string decoded via args[0].option yields a byte array whose length != 16. Typical mismatch: 32 hex chars = 16 bytes (valid); 16 hex chars = 8 bytes (invalid).
Common situations: Hex/UTF8/Base64 option selected wrongly for the key; pasting a key measured in characters rather than bytes; using an 8-byte DES-style key.
Related errors
- Invalid key length: ${key.length} bytes XTEA requires a key
- Invalid key length: ${key.length} bytes. XSalsa20 uses a ke
- Invalid IV length: ${iv.length} bytes XTEA uses an IV lengt
- Invalid number of rounds: ${rounds} Rounds must be an integ
- Invalid IV length: ${iv.length} bytes XTEA uses an IV lengt
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/72be3230723623b9.
Report an issue: GitHub.