gchq/CyberChef · error · OperationError

IV must be 8 bytes (currently " + iv.length + " bytes)

Error message

IV must be 8 bytes (currently " + iv.length + " bytes)

What it means

RFC 3394 wrap uses a fixed 8-byte IV/integrity value (conventionally A6A6A6A6A6A6A6A6). AESKeyWrap requires args[1] to convert to exactly 8 bytes and throws otherwise.

Source

Thrown at src/core/operations/AESKeyWrap.mjs:71

        ];
    }

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

        if (kek.length !== 16 && kek.length !== 24 && kek.length !== 32) {
            throw new OperationError("KEK must be either 16, 24, or 32 bytes (currently " + kek.length + " bytes)");
        }
        if (iv.length !== 8) {
            throw new OperationError("IV must be 8 bytes (currently " + iv.length + " bytes)");
        }
        const inputData = Utils.convertToByteString(input, inputType);
        if (inputData.length % 8 !== 0 || inputData.length < 16) {
            throw new OperationError("input must be 8n (n>=2) bytes (currently " + inputData.length + " bytes)");
        }

        const cipher = forge.cipher.createCipher("AES-ECB", kek);

        let A = iv;
        const R = [];
        for (let i = 0; i < inputData.length; i += 8) {
            R.push(inputData.substring(i, i + 8));
        }
        let cntLower = 1, cntUpper = 0;
        for (let j = 0; j < 6; j++) {
            for (let i = 0; i < R.length; i++) {
                cipher.start();
                cipher.update(forge.util.createBuffer(A + R[i]));

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Use the standard 8-byte IV A6A6A6A6A6A6A6A6 with IV format Hex (→ 8 bytes).
  2. Supply the exact 8-byte custom IV in the matching format if you need a non-default value.
  3. Re-check the IV format option against the string you entered.

Example fix

// before: IV "A6A6A6A6A6A6A6A6" format UTF8 → 16 bytes → throws
// after: set IV format to "Hex" → 8 bytes
Defensive patterns

Strategy: validation

Validate before calling

function validateWrapIv(ivBytes) {
  if (ivBytes.length !== 8) {
    throw new Error(`AES-KW IV must be 8 bytes, got ${ivBytes.length}`);
  }
}

Type guard

function isWrapIv(bytes) { return bytes instanceof Uint8Array && bytes.length === 8; }

Try / catch

try { aesKeyWrap(...); } catch (e) { if (/IV must be 8 bytes/.test(e.message)) {/* fix IV format */} else throw e; }

Prevention

When it happens

Trigger: The IV argument converts to a byte string whose length is not 8 — e.g. the default A6A6A6A6A6A6A6A6 entered as hex while the format is UTF8 (16 bytes), or any other length supplied.

Common situations: IV format option (Hex/UTF8) does not match the pasted string; user entered a 16-byte AES-CBC-style IV by mistake; IV field left blank.

Related errors


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