我刚开始使用 .NET 和 C#。我正在尝试检查计算机证书是否存在。它是特定的无线证书。
到目前为止,这是我的代码:
public void Analyser_Load(object sender, EventArgs e)
{
X509Store store = new X509Store(StoreLocation.LocalMachine);
X509Certificate2Collection col = store.Certificates
.Find(X509FindType.FindBySubjectName, "MyCertName", false);
}
Run Code Online (Sandbox Code Playgroud)
小智 6
这有效:
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var certificates = store.Certificates.Find(
X509FindType.FindBySubjectName,
"subjectName",
false);
if (certificates != null && certificates.Count > 0)
{
Console.WriteLine("Certificate already exists");
}
Run Code Online (Sandbox Code Playgroud)