{"record":{"id":"ed87577713ec15a4","repo":"peass-ng/PEASS-ng","slug":"key-length-not-128-192-256-bits","errorCode":null,"errorMessage":"Key length not 128/192/256 bits.","messagePattern":"Key length not 128/192/256 bits\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/AesEngine.cs","lineNumber":293,"sourceCode":"        private static uint SubWord(uint x)\n        {\n            return (uint)S[x & 255]\n                | (((uint)S[(x >> 8) & 255]) << 8)\n                | (((uint)S[(x >> 16) & 255]) << 16)\n                | (((uint)S[(x >> 24) & 255]) << 24);\n        }\n\n        /**\n        * Calculate the necessary round keys\n        * The number of calculations depends on key size and block size\n        * AES specified a fixed block size of 128 bits and key sizes 128/192/256 bits\n        * This code is written assuming those are the only possible values\n        */\n        private uint[][] GenerateWorkingKey(byte[] key, bool forEncryption)\n        {\n            int keyLen = key.Length;\n            if (keyLen < 16 || keyLen > 32 || (keyLen & 7) != 0)\n                throw new ArgumentException(\"Key length not 128/192/256 bits.\");\n\n            int KC = keyLen >> 2;\n            this.ROUNDS = KC + 6;  // This is not always true for the generalized Rijndael that allows larger block sizes\n\n            uint[][] W = new uint[ROUNDS + 1][]; // 4 words in a block\n            for (int i = 0; i <= ROUNDS; ++i)\n            {\n                W[i] = new uint[4];\n            }\n\n            switch (KC)\n            {\n                case 4:\n                    {\n                        uint t0 = Pack.LE_To_UInt32(key, 0); W[0][0] = t0;\n                        uint t1 = Pack.LE_To_UInt32(key, 4); W[0][1] = t1;\n                        uint t2 = Pack.LE_To_UInt32(key, 8); W[0][2] = t2;\n                        uint t3 = Pack.LE_To_UInt32(key, 12); W[0][3] = t3;","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/AesEngine.cs#L275-L311","documentation":"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].","triggerScenarios":"Calling Init(true/false, KeyParameter) with a key byte[] of any length other than 16/24/32, e.g. 15, 17, 64 bytes.","commonSituations":"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.","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)"],"exampleFix":"// before\ncipher.Init(true, new KeyParameter(passphrase));\n// after\nbyte[] key = new byte[16]; // or derive via KDF\nArray.Copy(passphrase, key, Math.Min(passphrase.Length, 16));\ncipher.Init(true, new KeyParameter(key));","handlingStrategy":"validation","validationCode":"if (key == null || (key.Length != 16 && key.Length != 24 && key.Length != 32)) throw new ArgumentException(\"AES key must be 16/24/32 bytes\");","typeGuard":"static bool IsValidAesKey(byte[] key) => key != null && (key.Length == 16 || key.Length == 24 || key.Length == 32);","tryCatchPattern":"try { cipher.Init(forEncryption, new KeyParameter(key)); } catch (ArgumentException ex) { /* report invalid key length */ }","preventionTips":["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"],"tags":["csharp","cryptography","aes","argument-validation"],"backgroundTag":"invalid-cipher-key-length","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}