2

我有一个 pfx 文件。当我使用文件流读取这个 pfx 文件时。当我只提供原始字节创建 X509Certificate2 时,它可以工作。但是当我尝试使用密码和标志创建 X509Certificate2 时,我收到一个异常消息“指定的网络密码不正确”。

第二个 X509Certificate2 构造失败,异常:“指定的网络密码不正确”虽然密码正确。

using (FileStream stream = new FileStream(@"D:\MyKey.pfx", FileMode.Open))
{
    int length = (int)stream.Length;
    byte[] certBytes = new byte[length];
    stream.Read(certBytes, 0, length);

    X509Certificate2 finalCert0 = new X509Certificate2(certBytes);
    X509Certificate2 finalCert1 = new X509Certificate2(certBytes, "venki", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
}
4

1 回答 1

0

刚刚有同样的经历,我删除了证书文件并重新复制了文件,它工作了。我恢复了旧文件,它以同样的方式失败。比较文件发现文件完全不同,有些文件已损坏。

于 2012-06-07T16:55:29.533 回答