{"record":{"id":"8fe0210cc17068f3","repo":"peass-ng/PEASS-ng","slug":"invalid-parameter-passed-to-aes-init","errorCode":null,"errorMessage":"invalid parameter passed to AES init - ","messagePattern":"invalid parameter passed to AES init - ","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/AesEngine.cs","lineNumber":455,"sourceCode":"        {\n        }\n\n        /**\n        * initialise an AES cipher.\n        *\n        * @param forEncryption whether or not we are for encryption.\n        * @param parameters the parameters required to set up the cipher.\n        * @exception ArgumentException if the parameters argument is\n        * inappropriate.\n        */\n        public virtual void Init(\n            bool forEncryption,\n            ICipherParameters parameters)\n        {\n            KeyParameter keyParameter = parameters as KeyParameter;\n\n            if (keyParameter == null)\n                throw new ArgumentException(\"invalid parameter passed to AES init - \"\n                    + Platform.GetTypeName(parameters));\n\n            WorkingKey = GenerateWorkingKey(keyParameter.GetKey(), forEncryption);\n\n            this.forEncryption = forEncryption;\n            this.s = Arrays.Clone(forEncryption ? S : Si);\n        }\n\n        public virtual string AlgorithmName\n        {\n            get { return \"AES\"; }\n        }\n\n        public virtual bool IsPartialBlockOkay\n        {\n            get { return false; }\n        }\n","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/AesEngine.cs#L437-L473","documentation":"Thrown by AesEngine.Init when the ICipherParameters passed in is not a KeyParameter (i.e. inappropriate for AES), meaning the caller supplied wrong or missing keying parameters rather than a cipher-key object.","triggerScenarios":"Calling Init(forEncryption, parameters) with ParametersWithIV, AeadParameters, a null parameter reference, or any non-KeyParameter object; note AES block cipher itself takes raw KeyParameter (IVs belong in a mode wrapper).","commonSituations":"Passing ParametersWithIV directly to AesEngine instead of wrapping it in GcmBlockCipher/CbcBlockCipher; passing null parameters; migrating code from another cipher API.","solutions":["Pass a KeyParameter: cipher.Init(forEncryption, new KeyParameter(keyBytes))","If you need an IV, wrap the engine in a mode: new CbcBlockCipher(engine) with ParametersWithIV","Handle parameters is null explicitly before calling Init"],"exampleFix":"// before\ncipher.Init(true, new ParametersWithIV(null, iv));\n// after\ncipher.Init(true, new KeyParameter(keyBytes)); // IV via CBC wrapper\nvar cbc = new CbcBlockCipher(new AesEngine());\ncbc.Init(true, new ParametersWithIV(new KeyParameter(keyBytes), iv));","handlingStrategy":"type-guard","validationCode":"if (parameters is not KeyParameter) throw new ArgumentException(\"AES Init requires KeyParameter\");","typeGuard":"static bool IsKeyParameter(ICipherParameters p) => p is KeyParameter;","tryCatchPattern":"try { cipher.Init(forEncryption, parameters); } catch (ArgumentException ex) { /* inspect ex.Message for the offending type name */ }","preventionTips":["Pass KeyParameter for the raw AES block cipher; IVs go into mode wrappers","Never pass null ICipherParameters to AES Init","Document that modes (CBC/GCM) accept ParametersWithIV, not the bare engine"],"tags":["csharp","cryptography","aes","wrong-parameter-type"],"backgroundTag":"invalid-cipher-parameters","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}