1

I've recently started my first project in C#, and it's a big one. I'm creating a Minecraft server by reading the protocol and doing it all myself. I've come a long way, but now I need to generate an RSA key pair so I can encrypt and decrypt data on the socket.

I've created a new RSACryptoServiceProvider using new RSACryptoServiceProvider(2048), but when I go to export using ToXmlString(), it gives the following PlatformNotSupportedException error:

error

Is there any alternatives to read the public key of the RSA I just generated? I am using .NET Core 2.2 if that helps. Thanks!

Jacob Gunther
  • 351
  • 5
  • 14

2 Answers2

4

ToXmlString() is not supported in .Net Core 2.2, you can export your public and private keys in standard PEM format. Here is the sample code on stackoverflow : Exporting a private key Exporting a public key

Community
  • 1
  • 1
Majid Kiani
  • 136
  • 3
0

If you insist on using ToXmlString then you can install the 3.0 preview builds. (3.0 is supposed to finish being in preview and be done in the next couple of weeks, FWIW)

Alternatively, you can use the ExportParameters method and format the output structure into any encoding that you are capable of reading back in.

But you should definitely use RSA.Create and (unless actually doing interop with Windows CAPI) never use RSACryptoServiceProvider.

bartonjs
  • 30,352
  • 2
  • 71
  • 111