.NET Core 2.0 RSA PlatformNotSupportedException

.NET Core 2.0 RSA PlatformNotSupportedException

我正在尝试使用此代码生成 public 和私钥,我在 Windows 10

上使用 .NET Core 2

到目前为止,我在 运行 这段代码中没有成功,它编译得很好,但是当我到达 rsa.ToXmlString 行时,它会抛出一个 PlatformNotSupportedException 并且当我在堆栈上的另一个答案中阅读时溢出解决方案使用的是 System.Security.Cryptography.Algorithms,他们在下面显示了我在此处使用的几乎完全相同的代码。

        using (RSA rsa = RSA.Create())
        {
            rsa.KeySize = 1024;

            privateKey = rsa.ToXmlString(true);
            publicKey = rsa.ToXmlString(false);
        }

错误:

如此处所示,它确实显示在他们的 API 浏览器中,因此必须支持它,对吗?

有没有人有类似的问题?或者有人对此有解决办法吗? 我必须使用 .NET Core,所以不建议使用 .NET 4.6

.Net Core 没有 toXmlString()fromXmlString 方法。但你可以使用 extension

解决方法: #874, #23686

更新:

在 .NET Core 3.0

中向 RSADSA 添加了 ToXmlStringFromXmlString 实现

RSA& DSA 个示例。

看起来终于在 .NET Core 3.0 中实现了:https://github.com/dotnet/corefx/pull/37593