peass-ng/PEASS-ng · error · ArgumentException
Key length not 128/192/256 bits.
Error message
Key length not 128/192/256 bits.
What it means
AesEngine.GenerateWorkingKey throws this ArgumentException when the AES key byte[] length is not 16, 24, or 32 bytes. AES only supports 128/192/256-bit keys; the guard also rejects lengths not a multiple of 8 or outside [16,32].
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/AesEngine.cs:293
private static uint SubWord(uint x)
{
return (uint)S[x & 255]
| (((uint)S[(x >> 8) & 255]) << 8)
| (((uint)S[(x >> 16) & 255]) << 16)
| (((uint)S[(x >> 24) & 255]) << 24);
}
/**
* Calculate the necessary round keys
* The number of calculations depends on key size and block size
* AES specified a fixed block size of 128 bits and key sizes 128/192/256 bits
* This code is written assuming those are the only possible values
*/
private uint[][] GenerateWorkingKey(byte[] key, bool forEncryption)
{
int keyLen = key.Length;
if (keyLen < 16 || keyLen > 32 || (keyLen & 7) != 0)
throw new ArgumentException("Key length not 128/192/256 bits.");
int KC = keyLen >> 2;
this.ROUNDS = KC + 6; // This is not always true for the generalized Rijndael that allows larger block sizes
uint[][] W = new uint[ROUNDS + 1][]; // 4 words in a block
for (int i = 0; i <= ROUNDS; ++i)
{
W[i] = new uint[4];
}
switch (KC)
{
case 4:
{
uint t0 = Pack.LE_To_UInt32(key, 0); W[0][0] = t0;
uint t1 = Pack.LE_To_UInt32(key, 4); W[0][1] = t1;
uint t2 = Pack.LE_To_UInt32(key, 8); W[0][2] = t2;
uint t3 = Pack.LE_To_UInt32(key, 12); W[0][3] = t3;View on GitHub (pinned to 53fb989abc)
Solutions
- Ensure the key byte[] is exactly 16, 24, or 32 bytes
- Derive a correctly-sized key with a KDF (e.g. PBE/PKCS5 or HKDF) instead of a raw passphrase
- Verify encoding/decoding of the key material (hex vs base64, trimming whitespace/newlines)
Example fix
// before cipher.Init(true, new KeyParameter(passphrase)); // after byte[] key = new byte[16]; // or derive via KDF Array.Copy(passphrase, key, Math.Min(passphrase.Length, 16)); cipher.Init(true, new KeyParameter(key));
Defensive patterns
Strategy: validation
Validate before calling
if (key == null || (key.Length != 16 && key.Length != 24 && key.Length != 32)) throw new ArgumentException("AES key must be 16/24/32 bytes"); Type guard
static bool IsValidAesKey(byte[] key) => key != null && (key.Length == 16 || key.Length == 24 || key.Length == 32);
Try / catch
try { cipher.Init(forEncryption, new KeyParameter(key)); } catch (ArgumentException ex) { /* report invalid key length */ } Prevention
- Derive keys with a KDF sized explicitly to 16/24/32 bytes
- Never use raw passphrases as AES keys
- Log key.Length (not key content) when debugging key errors
When it happens
Trigger: Calling Init(true/false, KeyParameter) with a key byte[] of any length other than 16/24/32, e.g. 15, 17, 64 bytes.
Common situations: Base64/hex decoding mistakes yielding a wrong-length key, user-supplied passphrases used directly as keys, or AES-256 keys passed to code assuming 128-bit.
Related errors
- Keys > 32 are not supported
- 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
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/ed87577713ec15a4.
Report an issue: GitHub.