Q:

Get X509Certificate2 Private and Public keys

I have an existing application in .NET 4.5 where I use X509Certificate2 private and public keys. I am migrating it to .net core. I am not getting how to read the private and public key values into XML format. I have below code in .NET 4.5 
var PublicKey = certificate.PublicKey.Key.ToXmlString(false);
var PrivateKey = certificate.PrivateKey.ToXmlString(true);

How do I achieve the same in .net core as the PrivateKey property is removed? 
I am aware of the ImportParameters and ExportParameters methods to convert into XML strings. But what I am looking at is accessing PublicKey.Key and PrivateKey properties which gets me the AsymmetricAlgorithm object which could be casted to RSACrypoServiceProvider. 
In .netCore there are methods GetRSAPublicKey and GetRSAPrivateKey, they return RSACng objects. The other side of the application which uses this certificate verifies data using RSACryptoServiceProvider.

A:

X509Certificate2.PrivateKey and PublicKey.Key were not brought over to .NET Core precisely because everyone cast them to RSACryptoServiceProvider.  While you get an RSACng on Windows, it's an RSAOpenSsl on Linux.
You should really just change all of the type references to RSA, since .NET 4.6 (and .NET Core 1.0) corrected the RSA base class to expose all of the required Sign/Verify//Encrypt/Decrypt methods.
.NET Core does not have the ability to read or write keys in the XML format. Even though the methods exist again for .NET Core 2.0 they just throw a PlatformNotSupportedException, since there's a circular dependency:

Cryptography.Algorithms -> XML
XML -> Networking (including TLS)
Networking/TLS -> X509Certificates
X509Certificates -> Cryptography.Algorithms

If you need the XML serialization of asymmetric keys you'll need to write it into your own libraries.

