{"record":{"id":"ec83a7a1d978f260","repo":"gchq/CyberChef","slug":"invalid-key-length-key-length-bytes-blowfish","errorCode":null,"errorMessage":"Invalid key length: ${key.length} bytes\n\nBlowfish's key length needs to be between 4 and 56 bytes (32-448 bits).","messagePattern":"Invalid key length: (.+?) bytes\n\nBlowfish's key length needs to be between 4 and 56 bytes \\(32-448 bits\\)\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/BlowfishDecrypt.mjs","lineNumber":74,"sourceCode":"                \"value\": [\"Raw\", \"Hex\"]\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.convertToByteString(args[0].string, args[0].option),\n            iv = Utils.convertToByteString(args[1].string, args[1].option),\n            mode = args[2],\n            inputType = args[3],\n            outputType = args[4];\n\n        if (key.length < 4 || key.length > 56) {\n            throw new OperationError(`Invalid key length: ${key.length} bytes\n\nBlowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);\n        }\n\n        if (mode !== \"ECB\" && iv.length !== 8) {\n            throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes.`);\n        }\n\n        input = Utils.convertToByteString(input, inputType);\n\n        const decipher = Blowfish.createDecipher(key, mode);\n        decipher.start({iv: iv});\n        decipher.update(forge.util.createBuffer(input));\n        const result = decipher.finish();\n\n        if (result) {\n            return outputType === \"Hex\" ? decipher.output.toHex() : decipher.output.getBytes();\n        } else {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/BlowfishDecrypt.mjs#L56-L92","documentation":"Blowfish accepts a variable-length key between 4 and 56 bytes (32-448 bits). The operation converts args[0] to a byte string and throws this when its length is outside that range, since Blowfish's key schedule rejects keys shorter than 4 bytes or longer than 56 bytes.","triggerScenarios":"Calling BlowfishDecrypt.run with a key (args[0].string interpreted via args[0].option) whose byte length is < 4 or > 56.","commonSituations":"Using a too-short password as a key; specifying the wrong key encoding option (e.g. treating hex text as UTF-8 doubles the byte length); pasting a key with trailing whitespace/newline that changes length.","solutions":["Verify the key byte length is between 4 and 56 inclusive after applying the chosen input option.","Double-check the args[0].option (Hex/Base64/UTF8) matches how your key material is encoded.","Trim whitespace/newlines from user-supplied key strings before conversion."],"exampleFix":"// before\nkey option 'UTF8' with 'abc' (3 bytes)\n// after\nkey option 'UTF8' with 'abcd' (4 bytes)","handlingStrategy":"validation","validationCode":"const keyBytes = Utils.convertToByteString(args[0].string, args[0].option);\nif (keyBytes.length < 4 || keyBytes.length > 56) {\n  throw new Error(`Blowfish key length ${keyBytes.length} out of range`);\n}","typeGuard":"function isValidBlowfishKey(len) { return len >= 4 && len <= 56; }","tryCatchPattern":null,"preventionTips":["Compute the key byte length under the same encoding option you will pass to the operation.","Trim whitespace/newlines from key input.","Prefer a KDF to produce a known-length key."],"tags":["crypto","blowfish","key-length","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}