【问题标题】:Certificate is missing from X509Store.Certificates collectionX509Store.Certificates 集合中缺少证书
【发布时间】:2017-05-21 07:41:30
【问题描述】:

我正在我的 PC 上测试以下代码:

private static void Main(string[] args)
{
    X509Store x509Store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

    x509Store.Open(OpenFlags.ReadOnly);

    foreach (var x509StoreCertificate in x509Store.Certificates)
    {
        Console.WriteLine(x509StoreCertificate.Thumbprint);
    }

    x509Store.Close();

    Console.WriteLine("Finished.");
    Console.ReadLine();
}

当我分析控制台中显示的指纹列表时,我注意到我今天导入的一个证书没有出现在列表中。

我导入的证书是通过以下方式完成的:

  • 打开MMC 并添加Certificates 管理单元。
  • 我在Computer account 级别打开了管理单元,
  • 我在PersonalTrusted Root Certification Authorities 中都导入了.pfx 证书文件。

完成上述操作后,我可以在证书列表中看到我提到的两个区域的证书。事实上,当我运行以下 Powershell 脚本时:

cls
Set-Location Cert:\LocalMachine
dir -Recurse | where {$_.Thumbprint -ne $null -and $_.Thumbprint.ToLower() -eq "‎‎thumbprint omitted"}

它找到证书的两个位置,Directory: Microsoft.PowerShell.Security\Certificate::LocalMachine\My 是其中之一。

所以我不清楚为什么 C# 控制台应用程序没有在 Certificates 集合中列出此证书。

我可能错过了一些明显的东西,但我们将不胜感激。

【问题讨论】:

    标签: .net certificate x509


    【解决方案1】:

    呃 :(

    原来我从证书属性对话框复制了指纹,这意味着它在字符串的开头有„,我最初看不到。从指纹前面删除该段后,我的代码顺利找到了证书。

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 2021-12-04
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 2011-10-27
      相关资源
      最近更新 更多