peass-ng/PEASS-ng · error · ArgumentException
Keys > 32 are not supported
Error message
Keys > 32 are not supported
What it means
Blake2s is a 256-bit hash whose keyed mode (MAC-style) accepts keys of at most 32 bytes. The Blake2sDigest(byte[] key) constructor validates the key length and throws ArgumentException when it exceeds 32 bytes, because the key is copied into the 64-byte internal buffer and the Blake2s parameter block simply cannot encode a longer key.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Blake2sDigest.cs:181
Init();
}
/**
* BLAKE2s for authentication ("Prefix-MAC mode").
* <p/>
* After calling the doFinal() method, the key will remain to be used for
* further computations of this instance. The key can be overwritten using
* the clearKey() method.
*
* @param key a key up to 32 bytes or null
*/
public Blake2sDigest(byte[] key)
{
buffer = new byte[BLOCK_LENGTH_BYTES];
if (key != null)
{
if (key.Length > 32)
throw new ArgumentException("Keys > 32 are not supported");
this.key = new byte[key.Length];
Array.Copy(key, 0, this.key, 0, key.Length);
keyLength = key.Length;
Array.Copy(key, 0, buffer, 0, key.Length);
bufferPos = BLOCK_LENGTH_BYTES; // zero padding
}
digestLength = 32;
Init();
}
/**
* BLAKE2s with key, required digest length, salt and personalization.
* <p/>
* After calling the doFinal() method, the key, the salt and the personal
* string will remain and might be used for further computations with this
* instance. The key can be overwritten using the clearKey() method, theView on GitHub (pinned to 53fb989abc)
Solutions
- Truncate or derive the key to at most 32 bytes before passing it: use a KDF (e.g. HKDF/PBKDF2) with a 32-byte output, or take key.AsSpan(0, 32).ToArray().
- If a longer key must be supported, switch to Blake2bDigest, whose keyed mode accepts up to 64 bytes.
- If the byte array is not meant to be a key, pass null or use the keyless constructor and feed the data via BlockUpdate().
Example fix
// before
byte[] longKey = File.ReadAllBytes("secret.pem"); // > 32 bytes
var digest = new Blake2sDigest(longKey);
// after
byte[] key32 = new byte[32];
Array.Copy(longKey, key32, 32); // or derive via HKDF
var digest = new Blake2sDigest(key32); Defensive patterns
Strategy: validation
Validate before calling
if (key == null || key.Length > 32)
throw new ArgumentOutOfRangeException(nameof(key), "Blake2s keys must be 1-32 bytes");
var digest = new Blake2sDigest(key); Type guard
static bool IsValidBlake2sKey(byte[] key) => key != null && key.Length <= 32;
Try / catch
try { var d = new Blake2sDigest(key); }
catch (ArgumentException ex) { /* fall back to keyless hash or derived 32-byte key */ } Prevention
- Derive keys with a KDF outputting exactly 32 bytes
- Never pass PEM/DER blobs directly as digest keys
- Prefer Blake2bDigest when >32-byte keys are required
When it happens
Trigger: Calling new Blake2sDigest(byte[] key) with a key array whose Length > 32 (e.g. a 64-byte HMAC key, an RSA/PEM-derived key blob, or raw user-supplied secret bytes).
Common situations: Developers reuse a long symmetric key or an entire key file (PEM/DER bytes) as the Blake2s key instead of hashing/deriving a 32-byte subkey; porting code from Blake2b (which allows 64-byte keys) to Blake2s; concatenating salt+secret into one key buffer.
Related errors
- Invalid digest length (required: 1 - 32)
- Salt length must be exactly 8 bytes
- Personalization length must be exactly 8 bytes
- Keys > 32 bytes are not supported
- BLAKE2s digest bit length must be a multiple of 8 and not gr
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/a0666092ac23a346.
Report an issue: GitHub.