Disposing of the AesGcm instance happens unconditionally (even when it was passed in as a parameter) https://github.com/PowerShellLibrary/Crypto.AES/blob/017c3f4554c879381771f5d36073bcbd311884de/Crypto.AES/Public/Protect-Data.ps1#L34 This might cause unexpected behavior.