{"record":{"id":"f2a6ba559b54ea88","repo":"gchq/CyberChef","slug":"unable-to-decrypt-using-this-key","errorCode":null,"errorMessage":"Unable to decrypt using this key","messagePattern":"Unable to decrypt using this key","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/XXTEADecrypt.mjs","lineNumber":51,"sourceCode":"                \"name\": \"Key\",\n                \"type\": \"toggleString\",\n                \"value\": \"\",\n                \"toggleValues\": [\"Hex\", \"UTF8\", \"Latin1\", \"Base64\"]\n            },\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const key = new Uint8Array(Utils.convertToByteArray(args[0].string, args[0].option));\n        try {\n            return decrypt(new Uint8Array(input), key).buffer;\n        } catch (err) {\n            throw new OperationError(\"Unable to decrypt using this key\");\n        }\n    }\n\n}\n\nexport default XXTEADecrypt;\n","sourceCodeStart":33,"sourceCodeEnd":58,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/XXTEADecrypt.mjs#L33-L58","documentation":"Thrown by XXTEADecrypt.run when the underlying decrypt(new Uint8Array(input), key) raises any exception. The catch is broad: it collapses every failure (wrong key, malformed ciphertext, incorrect block structure) into the single message 'Unable to decrypt using this key', discarding the original error detail.","triggerScenarios":"The input is not a valid XXTEA-encrypted byte stream for the supplied key, or the key/input length violates XXTEA constraints (XXTEA operates on a 32-bit-word array; an input whose byte length is not a multiple of 4, or is too short, can fail).","commonSituations":"Wrong key; ciphertext truncated or prepended with extra bytes (header, IV); input not first converted to the right byte format; decrypting data that was encrypted with a different XXTEA variant.","solutions":["Confirm the key is the exact key used to encrypt.","Ensure the input is the raw XXTEA ciphertext bytes (ArrayBuffer) with no headers/padding; convert via the correct input type.","Check that the byte length is a positive multiple of 4 (XXTEA word size).","If you only have the cipher text and do not know the variant, this error alone cannot distinguish wrong-key from malformed-input — try the original key/format first."],"exampleFix":"// before: input is hex string, not converted to bytes\nchef.bake(hexCiphertext, [{op:\"XXTEA Decrypt\", args:[{string:key,option:\"Hex\"}]}]);\n// after: convert hex to bytes first, then decrypt\nchef.bake(hexCiphertext,\n  [{op:\"From Hex\"}, {op:\"XXTEA Decrypt\", args:[{string:key,option:\"Hex\"}]}]);","handlingStrategy":"try-catch","validationCode":"function isValidXxteaInput(bytes, key) {\n  if (!(bytes.byteLength > 0 && bytes.byteLength % 4 === 0)) return false;\n  if (key.length !== 16) return false; // typical XXTEA key constraint\n  return true;\n}","typeGuard":"const isXxteaWordAligned = (ab) => ab.byteLength > 0 && ab.byteLength % 4 === 0;","tryCatchPattern":"try { result = chef.bake(input, [{op:\"From Hex\"},{op:\"XXTEA Decrypt\",args:[...]}]); } catch (e) { if (/Unable to decrypt using this key/.test(e.message)) { /* wrong key or malformed ciphertext */ } else throw e; }","preventionTips":["Verify the key matches the encryption key exactly.","Feed raw ciphertext bytes (ArrayBuffer), not hex/text; convert first.","Ensure the byte length is a positive multiple of 4.","XXTEA has no integrity check, so this error cannot distinguish wrong-key from malformed-input."],"tags":["xxtea","crypto","decrypt","key-mismatch"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}