{"record":{"id":"8f498a2c61208d1f","repo":"gchq/CyberChef","slug":"invalid-key-length-key-length-bytes-blowfish-8f498a","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/BlowfishEncrypt.mjs","lineNumber":74,"sourceCode":"                \"value\": [\"Hex\", \"Raw\"]\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 cipher = Blowfish.createCipher(key, mode);\n        cipher.start({iv: iv});\n        cipher.update(forge.util.createBuffer(input));\n        cipher.finish();\n\n        if (outputType === \"Hex\") {\n            return cipher.output.toHex();\n        } else {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/BlowfishEncrypt.mjs#L56-L92","documentation":"Same key-length contract as BlowfishDecrypt: the Blowfish key schedule requires 4-56 bytes (32-448 bits). BlowfishEncrypt.run throws when the converted key length falls outside that range.","triggerScenarios":"Calling BlowfishEncrypt.run with args[0] key whose byte length is < 4 or > 56 after the args[0].option conversion.","commonSituations":"Short password-derived key; wrong key encoding option inflating/deflating length; trailing newline in the key string.","solutions":["Ensure the key byte length is 4-56 inclusive.","Confirm args[0].option matches the key's encoding.","Strip whitespace/newlines from user-supplied keys."],"exampleFix":"// before\nkey option 'UTF8' with 'abc'\n// after\nkey option 'UTF8' with 'abcd'","handlingStrategy":"validation","validationCode":"const keyBytes = Utils.convertToByteString(args[0].string, args[0].option);\nif (keyBytes.length < 4 || keyBytes.length > 56) throw new Error('Blowfish key out of range');","typeGuard":"function isValidBlowfishKey(len) { return len >= 4 && len <= 56; }","tryCatchPattern":null,"preventionTips":["Pin key length to 16 or 32 bytes for simplicity.","Confirm the key encoding option.","Avoid raw passwords; derive keys with a KDF."],"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"}