gchq/CyberChef · error · OperationError

Invalid IV length: ${iv.length} bytes. Expected 8 bytes.

Error message

Invalid IV length: ${iv.length} bytes. Expected 8 bytes.

What it means

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.

Source

Thrown at src/core/operations/BlowfishEncrypt.mjs:80

     * @param {string} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        const key = Utils.convertToByteString(args[0].string, args[0].option),
            iv = Utils.convertToByteString(args[1].string, args[1].option),
            mode = args[2],
            inputType = args[3],
            outputType = args[4];

        if (key.length < 4 || key.length > 56) {
            throw new OperationError(`Invalid key length: ${key.length} bytes

Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);
        }

        if (mode !== "ECB" && iv.length !== 8) {
            throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes.`);
        }

        input = Utils.convertToByteString(input, inputType);

        const cipher = Blowfish.createCipher(key, mode);
        cipher.start({iv: iv});
        cipher.update(forge.util.createBuffer(input));
        cipher.finish();

        if (outputType === "Hex") {
            return cipher.output.toHex();
        } else {
            return cipher.output.getBytes();
        }
    }

}

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide exactly an 8-byte IV for CBC/CFB/OFB/CTR modes.
  2. Match args[1].option to the IV encoding.
  3. Use ECB only if you deliberately want no IV.

Example fix

// before
mode='CBC', iv ''
// after
mode='CBC', iv option 'Hex' with '0011223344556677'
Defensive patterns

Strategy: validation

Validate before calling

const ivBytes = Utils.convertToByteString(args[1].string, args[1].option);
if (args[2] !== 'ECB' && ivBytes.length !== 8) throw new Error('IV must be 8 bytes');

Type guard

function isValidBlowfishIV(mode, len) { return mode === 'ECB' || len === 8; }

Prevention

When it happens

Trigger: Calling BlowfishEncrypt.run with mode other than ECB and args[1] IV whose byte length differs from 8.

Common situations: Using a 16-byte IV from another cipher; wrong IV encoding option; empty IV for CBC/CFB/OFB.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/c53b1be70553bebb. Report an issue: GitHub.