【问题标题】:Importing the Private Key from the .pfx file从 .pfx 文件导入私钥
【发布时间】:2013-04-22 01:50:26
【问题描述】:

如何从 .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

如何获取字符串格式的私钥?

【问题讨论】:

    标签: c# encryption certificate key private


    【解决方案1】:

    我还没有测试过,但是 MSDN 文档说你正在使用以下代码获取私钥

    string private_key = cert.PrivateKey.ToXmlString(false);
    Console.WriteLine(private_key);
    

    http://msdn.microsoft.com/de-de/library/system.security.cryptography.x509certificates.x509certificate2.privatekey.aspx

    【讨论】:

      猜你喜欢
      • 2013-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 2012-09-07
      • 2018-06-07
      • 2011-09-12
      相关资源
      最近更新 更多