gchq/CyberChef · error · OperationError
Invalid key length: ${key.length} bytes PRESENT uses a key
Error message
Invalid key length: ${key.length} bytes
PRESENT uses a key length of 10 bytes (80 bits) or 16 bytes (128 bits). What it means
Identical validation to error 547 but in the encrypt operation. The PRESENT block cipher requires a key of exactly 10 bytes (80 bits) or 16 bytes (128 bits). The encrypt operation validates the key length before calling encryptPRESENT.
Source
Thrown at src/core/operations/PRESENTEncrypt.mjs:77
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 10 && key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
PRESENT uses a key length of 10 bytes (80 bits) or 16 bytes (128 bits).`);
if (iv.length !== 8 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
PRESENT uses an IV length of 8 bytes (64 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteArray(input, inputType);
const output = encryptPRESENT(input, key, iv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default PRESENTEncrypt;
View on GitHub (pinned to 4290ea7539)
Solutions
- Provide exactly 10 or 16 bytes of key material
- Double-check the key encoding option (Hex vs UTF8 vs Base64) matches your key representation
- For hex keys, use 20 hex chars (10 bytes) or 32 hex chars (16 bytes) with the Hex option
Example fix
// before: key="aabbccddeeff0011", option="Hex" -> 8 bytes (FAILS) // after: key="aabbccddeeff00112233", option="Hex" -> 10 bytes (OK for 80-bit)
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check: validate key length before calling the operation
const keyBytes = Utils.convertToByteArray(keyString, keyOption);
if (keyBytes.length !== 10 && keyBytes.length !== 16) {
throw new Error(`Key must be 10 or 16 bytes, got ${keyBytes.length}. Check encoding option.`);
} Type guard
function isValidPresentKey(keyBytes) {
return keyBytes.length === 10 || keyBytes.length === 16;
} Prevention
- Verify the key encoding option matches the key string representation
- For hex keys, use 20 or 32 hex characters with the Hex option selected
- Account for multibyte UTF8 characters affecting byte count
When it happens
Trigger: The key argument, after convertToByteArray with the selected encoding option, yields a byte array whose length is not 10 or 16. Encoding mismatch is the most common cause — e.g., a hex key string interpreted as UTF8 doubles the effective byte count.
Common situations: User enters a hex key with the encoding option left on UTF8, producing the wrong byte count. User provides a key intended for a different cipher. Multibyte UTF8 characters inflate the byte count unexpectedly.
Related errors
- Invalid key length: ${key.length} bytes PRESENT uses a key
- Invalid IV length: ${iv.length} bytes PRESENT uses an IV le
- Invalid IV length: ${iv.length} bytes PRESENT uses an IV le
- Invalid key length: ${key.length} bytes Blowfish's key leng
- Invalid key length: ${key.length} bytes Blowfish's key leng
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/f7a7d3f6b7d34d54.
Report an issue: GitHub.