peass-ng/PEASS-ng · error · InvalidOperationException

AES engine not initialised

Error message

AES engine not initialised

What it means

ProcessBlock throws this InvalidOperationException when WorkingKey is null, i.e. EncryptBlock/DecryptBlock is attempted before Init was called successfully. AES requires the key schedule before any block can be processed.

Source

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

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

        public virtual int GetBlockSize()
        {
            return BLOCK_SIZE;
        }

        public virtual int ProcessBlock(
            byte[] input,
            int inOff,
            byte[] output,
            int outOff)
        {
            if (WorkingKey == null)
                throw new InvalidOperationException("AES engine not initialised");

            Check.DataLength(input, inOff, 16, "input buffer too short");
            Check.OutputLength(output, outOff, 16, "output buffer too short");

            UnPackBlock(input, inOff);

            if (forEncryption)
            {
                EncryptBlock(WorkingKey);
            }
            else
            {
                DecryptBlock(WorkingKey);
            }

            PackBlock(output, outOff);

            return BLOCK_SIZE;

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Call engine.Init(forEncryption, new KeyParameter(key)) before ProcessBlock
  2. Verify the earlier Init did not throw (it leaves WorkingKey null)
  3. Re-create or re-Init the engine after any failure

Example fix

// before
var engine = new AesEngine();
engine.ProcessBlock(input, 0, output, 0);
// after
var engine = new AesEngine();
engine.Init(true, new KeyParameter(key));
engine.ProcessBlock(input, 0, output, 0);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!initialized) cipher.Init(forEncryption, new KeyParameter(key));

Type guard

static bool IsAesReady(AesEngine e) => e != null; // WorkingKey is private; track init yourself

Try / catch

try { cipher.ProcessBlock(input, 0, output, 0); } catch (InvalidOperationException ex) { /* lazy-Init then retry */ }

Prevention

When it happens

Trigger: Calling ProcessBlock on a new AesEngine without Init, after Init threw (e.g. bad key length), or after the engine was reset without re-initializing.

Common situations: Deferred initialization logic that skips Init, an earlier Init exception swallowed by logging code, or sharing an engine instance across threads before it's initialized.

Related errors


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