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://learn.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!