【发布时间】: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级别打开了管理单元, - 我在
Personal和Trusted 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