.NET Core 2.0 RSA PlatformNotSupportedException

2019-02-17 12:49发布

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: enter image description here

As seen here it does show up in their API browser, so it has to be supported, right? enter image description here

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

1条回答
做个烂人
2楼-- · 2019-02-17 13:19

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

Workarounds: #874, #23686

查看更多
登录 后发表回答