如何从.pfx文件导入证书的私钥?我有这段代码:
X509Certificate2 cert = new X509Certificate2("C:/amazon.pfx", "hello", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
string private_key = cert.PrivateKey.ToString();
Console.WriteLine(private_key);
然而,输出是:
System.Security.Cryptography.RSACryptoServiceProvider
如何以字符串格式获取私钥?
答案 0 :(得分:6)
我还没有测试过,但是MSDN文档说您使用以下代码获取私钥
string private_key = cert.PrivateKey.ToXmlString(false);
Console.WriteLine(private_key);