Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

c# - .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: 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...