{"record":{"id":"c53b1be70553bebb","repo":"gchq/CyberChef","slug":"invalid-iv-length-iv-length-bytes-expected-8-c53b1b","errorCode":null,"errorMessage":"Invalid IV length: ${iv.length} bytes. Expected 8 bytes.","messagePattern":"Invalid IV length: (.+?) bytes\\. Expected 8 bytes\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/BlowfishEncrypt.mjs","lineNumber":80,"sourceCode":"     * @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 {\n            return cipher.output.getBytes();\n        }\n    }\n\n}\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/BlowfishEncrypt.mjs#L62-L98","documentation":"Identical contract to BlowfishDecrypt: a non-ECB Blowfish mode needs an 8-byte IV. BlowfishEncrypt.run throws when mode != ECB and the IV byte length is not 8.","triggerScenarios":"Calling BlowfishEncrypt.run with mode other than ECB and args[1] IV whose byte length differs from 8.","commonSituations":"Using a 16-byte IV from another cipher; wrong IV encoding option; empty IV for CBC/CFB/OFB.","solutions":["Provide exactly an 8-byte IV for CBC/CFB/OFB/CTR modes.","Match args[1].option to the IV encoding.","Use ECB only if you deliberately want no IV."],"exampleFix":"// before\nmode='CBC', iv ''\n// after\nmode='CBC', iv option 'Hex' with '0011223344556677'","handlingStrategy":"validation","validationCode":"const ivBytes = Utils.convertToByteString(args[1].string, args[1].option);\nif (args[2] !== 'ECB' && ivBytes.length !== 8) throw new Error('IV must be 8 bytes');","typeGuard":"function isValidBlowfishIV(mode, len) { return mode === 'ECB' || len === 8; }","tryCatchPattern":null,"preventionTips":["Generate a fresh 8-byte IV per encryption.","Store the IV with the ciphertext for the decryptor.","Use ECB only with full awareness of its weaknesses."],"tags":["crypto","blowfish","iv-length","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}