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
The PRESENT block cipher requires a key of exactly 10 bytes (80 bits) or 16 bytes (128 bits) per ISO/IEC 29192-2. The decrypt operation validates this before calling decryptPRESENT and rejects any other key length. The most common cause is an encoding mismatch — the key string has the right character count but decodes to the wrong number of bytes.
Source
Thrown at src/core/operations/PRESENTDecrypt.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 = decryptPRESENT(input, key, iv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default PRESENTDecrypt;
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 the actual representation of your key
- If your key is in hex, ensure it is 20 hex chars (10 bytes) or 32 hex chars (16 bytes)
Example fix
// Key encoding mismatch: // before: key="0123456789abcdef", option="UTF8" -> 16 bytes (OK for 128-bit) // but key="0123456789abcdef", option="Hex" -> 8 bytes (FAILS) // after: key="0123456789abcdef0123456789abcdef", option="Hex" -> 16 bytes (OK)
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
- Always verify the key encoding option (Hex/UTF8/Base64) matches the key string representation
- For hex keys, use 20 hex chars (10 bytes) or 32 hex chars (16 bytes)
- Remember that multibyte UTF8 characters increase the 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. For example, a 20-character hex string (which is 10 bytes decoded) or a 32-character hex string (16 bytes) are correct; a 10-character hex string decodes to only 5 bytes and fails. A UTF8 key of 10 characters is 10 bytes, but a multibyte UTF8 key may have a different byte count.
Common situations: User enters a 16-character hex key but leaves the encoding option on 'UTF8', so it becomes 16 bytes instead of the intended 8. Or enters a key that is 8 bytes (for another cipher like DES) by mistake. Or provides an ASCII key where multibyte characters inflate the byte count.
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/39d59a1983aee33c.
Report an issue: GitHub.