Share via

PowerShell - System.Security.Cryptography.AesGcm not found despite required .NET version installed correctly

Anonymous
2021-06-19T17:00:38+00:00

Hello,

I need to use AesGcm class in PowerShell 5.1.19041.906 in Windows 10 (Version 20H2 (OS Build 19042.985) and by following the Microsoft documentation https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aesgcm?view=net-5.0 it requires that one of the following .NET software versions are installed:

Product Versions
.NET 5.0 6.0 Preview 3
.NET Core 3.0 3.1
.NET Standard 2.1

I installed Microsoft .NET Runtime - 5.0.7 (x64) from https://dotnet.microsoft.com/download/dotnet/5.0 but when I try to search the functions related AesGcm, I cannot find anything despite I call "Add-Type -Assembly System.Security". I also tried to install the other .NET products and versions reported but nothing.

The only things related to Aes I have are:

System.Security.Cryptography.Aes

System.Security.Cryptography.AesCng

System.Security.Cryptography.AesCryptoServiceProvider

System.Security.Cryptography.AesManaged

The piece of code I need to use is the following:

Add-Type -Assembly System.Security

$encrypted_value = ".. let's guess some encrypted value .."

$cipherStream = [System.IO.MemoryStream]::new($encrypted_value)
$cipherReader = [System.IO.BinaryReader]::new($cipherStream)
$nonSecretPayload = $cipherReader.ReadBytes(3) # Magic number 3
$nonce = $cipherReader.ReadBytes([System.Security.Cryptography.AesGcm]::NonceByteSizes.MinSize)

I get the following error:
Unable to find type [System.Security.Cryptography.AesGcm].
At line:1 char:34
+ ... $cipherReader.ReadBytes([System.Security.Cryptography.AesGcm]::NonceB ...
+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Security.Cryptography.AesGcm:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

How can I solve? Which .NET Product and version I need to install? Should I change manually the assembly references PowerShell must refer to? If so, how can I do?

Thanks for help!
Windows for home | Windows 10 | Settings

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2021-06-20T16:41:02+00:00

Hi,

Thank you for writing to Microsoft Community Forums.

However, for concern/queries related to PowerShell - System.Security.Cryptography.AesGcm, let me help to point you in the right direction. I would suggest you to post your query in****MSDN Forum where you will find professionals with expertise on using PowerShell command and that would be the appropriate forum

Regards,

Aditya Roy

Microsoft Community – Moderator

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2021-06-21T11:25:20+00:00

    Thank you for the answer.

    I posted the question on MSDN Forum at this link: https://docs.microsoft.com/en-us/answers/questions/444991/powershell-systemsecuritycryptographyaesgcm-not-fo.html

    Was this answer helpful?

    0 comments No comments