peass-ng/PEASS-ng · error · ArgumentException

invalid parameter passed to AES init -

Error message

invalid parameter passed to AES init - 

What it means

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.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/AesEngine.cs:455

        {
        }

        /**
        * initialise an AES cipher.
        *
        * @param forEncryption whether or not we are for encryption.
        * @param parameters the parameters required to set up the cipher.
        * @exception ArgumentException if the parameters argument is
        * inappropriate.
        */
        public virtual void Init(
            bool forEncryption,
            ICipherParameters parameters)
        {
            KeyParameter keyParameter = parameters as KeyParameter;

            if (keyParameter == null)
                throw new ArgumentException("invalid parameter passed to AES init - "
                    + Platform.GetTypeName(parameters));

            WorkingKey = GenerateWorkingKey(keyParameter.GetKey(), forEncryption);

            this.forEncryption = forEncryption;
            this.s = Arrays.Clone(forEncryption ? S : Si);
        }

        public virtual string AlgorithmName
        {
            get { return "AES"; }
        }

        public virtual bool IsPartialBlockOkay
        {
            get { return false; }
        }

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a KeyParameter: cipher.Init(forEncryption, new KeyParameter(keyBytes))
  2. If you need an IV, wrap the engine in a mode: new CbcBlockCipher(engine) with ParametersWithIV
  3. Handle parameters is null explicitly before calling Init

Example fix

// before
cipher.Init(true, new ParametersWithIV(null, iv));
// after
cipher.Init(true, new KeyParameter(keyBytes)); // IV via CBC wrapper
var cbc = new CbcBlockCipher(new AesEngine());
cbc.Init(true, new ParametersWithIV(new KeyParameter(keyBytes), iv));
Defensive patterns

Strategy: type-guard

Validate before calling

if (parameters is not KeyParameter) throw new ArgumentException("AES Init requires KeyParameter");

Type guard

static bool IsKeyParameter(ICipherParameters p) => p is KeyParameter;

Try / catch

try { cipher.Init(forEncryption, parameters); } catch (ArgumentException ex) { /* inspect ex.Message for the offending type name */ }

Prevention

When it happens

Trigger: 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).

Common situations: Passing ParametersWithIV directly to AesEngine instead of wrapping it in GcmBlockCipher/CbcBlockCipher; passing null parameters; migrating code from another cipher API.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/8fe0210cc17068f3. Report an issue: GitHub.