X509Store.Certificates 集合中缺少证书
Certificate is missing from X509Store.Certificates collection
我正在我的电脑上测试以下代码:
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
集合中列出此证书。
我可能刚刚错过了一些明显的东西,但我们将不胜感激。
呃:(
原来我从证书属性对话框中复制了指纹,这意味着它在字符串的开头有 „
,我最初看不到。从指纹前面删除该段后,我的代码顺利找到了证书。
我正在我的电脑上测试以下代码:
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
集合中列出此证书。
我可能刚刚错过了一些明显的东西,但我们将不胜感激。
呃:(
原来我从证书属性对话框中复制了指纹,这意味着它在字符串的开头有 „
,我最初看不到。从指纹前面删除该段后,我的代码顺利找到了证书。