Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...