Add-Type -AssemblyName System.Security
$CSPParam = New-Object System.Security.Cryptography.CspParameters
$CSPParam.KeyContainerName = "Test"
$RSA = New-Object System.Security.Cryptography.RSACryptoServiceProvider($CSPParam)
$PublicKey = $RSA.ToXmlString($False)
Created Public Key
Exception calling "ToXmlString" with "1" argument(s): "Operation is not supported on this platform."
At line:1 char:1
+ $PublicKey = $RSA.ToXmlString($False)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : PlatformNotSupportedException
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-rc.2
PSEdition Core
GitCommitId v6.0.0-rc.2
OS Microsoft Windows 10.0.17063
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I believe it is CoreFX limitation.
How can I get public key?
You can see .Net Framework implementation http://referencesource.microsoft.com/#mscorlib/system/security/cryptography/rsa.cs,fd15a0bacd426550
.Net Core is ToXmlString not support ?
@MuraAtVwnet It would appear it is not supported on .NET Core : https://github.com/dotnet/corefx/blob/c0df023a72954f72ab42387cf511f16f1a0f1db6/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSA.Xml.cs#L14 All that method does is throw a PlatformNotSupportedException exception.
T T
thank you