Reputation: 4607
How can I import the private key of a certificate from a .pfx file? I have this code:
X509Certificate2 cert = new X509Certificate2("C:/amazon.pfx", "hello", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
string private_key = cert.PrivateKey.ToString();
Console.WriteLine(private_key);
However, the output is:
System.Security.Cryptography.RSACryptoServiceProvider
How can I get the private key in string format?
Upvotes: 2
Views: 3455
Reputation: 2013
I haven't tested it, but the MSDN documentation says that you're getting the private key with the following code
string private_key = cert.PrivateKey.ToXmlString(false);
Console.WriteLine(private_key);
Upvotes: 6