简体   繁体   中英

.NET Core 2.0 RSA PlatformNotSupportedException

I am trying to use this code to generate a public and private key, I am using .NET Core 2 on Windows 10

So far I had no success in running this code, it compiles just fine but when I get to the rsa.ToXmlString line it drops with a PlatformNotSupportedException and as I read in another answer on stack overflow the solution was using System.Security.Cryptography.Algorithms and they showed the almost exact code that I use here down below.

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

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

Error: 在此输入图像描述

As seen here it does show up in their API browser, so it has to be supported, right? 在此输入图像描述

Does anyone have any similar problems? Or does anyone have a fix for this? I have to use .NET Core so don't suggest using .NET 4.6

.Net Core don't have the toXmlString() and fromXmlString method. but you can use an extension

Workarounds: #874 , #23686

Update:

Added ToXmlString and FromXmlString implementations to RSA and DSA in .NET Core 3.0

RSA & DSA examples.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM