{"record":{"id":"72be3230723623b9","repo":"gchq/CyberChef","slug":"invalid-key-length-key-length-bytes-xtea-requ","errorCode":null,"errorMessage":"Invalid key length: ${key.length} bytes\n\nXTEA requires a key length of 16 bytes (128 bits).\nMake sure you have specified the type correctly (e.g. Hex vs UTF8).","messagePattern":"Invalid key length: (.+?) bytes\n\nXTEA requires a key length of 16 bytes \\(128 bits\\)\\.\nMake sure you have specified the type correctly \\(e\\.g\\. Hex vs UTF8\\)\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/XTEADecrypt.mjs","lineNumber":84,"sourceCode":"                \"value\": 32,\n                \"min\": 1,\n                \"max\": 255\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const key = Utils.convertToByteArray(args[0].string, args[0].option),\n            iv = Utils.convertToByteArray(args[1].string, args[1].option),\n            [,, mode, inputType, outputType, padding, rounds] = args;\n\n        if (key.length !== 16)\n            throw new OperationError(`Invalid key length: ${key.length} bytes\n\nXTEA requires a key length of 16 bytes (128 bits).\nMake sure you have specified the type correctly (e.g. Hex vs UTF8).`);\n\n        if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== \"ECB\")\n            throw new OperationError(`Invalid IV length: ${iv.length} bytes\n\nXTEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).\nMake sure you have specified the type correctly (e.g. Hex vs UTF8).`);\n\n        if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)\n            throw new OperationError(`Invalid number of rounds: ${rounds}\n\nRounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.`);\n\n        // Default IV to null bytes if empty (like AES)\n        const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/XTEADecrypt.mjs#L66-L102","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: 16 hex chars -> 8 bytes\nargs:[{string:\"0123456789abcdef\",option:\"Hex\"}, ...]\n// after: 32 hex chars -> 16 bytes\nargs:[{string:\"0123456789abcdef0123456789abcdef\",option:\"Hex\"}, ...]","handlingStrategy":"validation","validationCode":"function xteaKeyRecipe(keyStr, keyOption) {\n  const key = Utils.convertToByteArray(keyStr, keyOption);\n  if (key.length !== 16) throw new Error(`XTEA key must be 16 bytes, got ${key.length}`);\n  return {string:keyStr, option:keyOption};\n}","typeGuard":"const isXteaKeyLen = (bytes) => bytes.length === 16;","tryCatchPattern":"try { chef.bake(data, recipe); } catch (e) { if (/key length/.test(e.message) && /XTEA/.test(e.message)) { /* fix key */ } else throw e; }","preventionTips":["Decode and assert 16-byte keys before baking.","Keep key format option consistent.","Derive keys via a KDF rather than padding short passphrases."],"tags":["xtea","crypto","key-length","operation-args"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}