dae*_*aai 14 c# vb.net powershell wizard x509certificate
您可以使用certmgr.msc中的向导(右键单击安装)将证书安装到证书库中吗?有谁知道如何通过使用向导/代码(pref.)/脚本"干净地"删除所有证书?
我希望能够从LocalMachine和/或CurrentUser商店中删除所有(我之前安装的),而不会留下任何残留物.
谢谢
Han*_*ans 14
您可以尝试使用X509Store.Net Framework中的相关类来从证书存储中删除证书.以下代码示例从当前用户的My store中删除证书:
// Use other store locations if your certificate is not in the current user store.
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite | OpenFlags.IncludeArchived);
// You could also use a more specific find type such as X509FindType.FindByThumbprint
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "yoursubjectname", false);
foreach (var cert in col)
{
Console.Out.WriteLine(cert.SubjectName.Name);
// Remove the certificate
store.Remove(cert);
}
store.Close();
Run Code Online (Sandbox Code Playgroud)
开始编辑: 根据评论部分中的评论,我用代码示例更新了我的答案,该代码示例显示了如何删除证书和链中的所有证书:
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "yoursubjectname", false);
X509Chain ch = new X509Chain();
ch.Build(col[0]);
X509Certificate2Collection allCertsInChain = new X509Certificate2Collection();
foreach (X509ChainElement el in ch.ChainElements)
{
allCertsInChain.Add(el.Certificate);
}
store.RemoveRange(allCertsInChain);
Run Code Online (Sandbox Code Playgroud)
结束编辑
希望这可以帮助.
老线程,但我只是使用 Win 7 按照下面的链接帖子操作,效果很好......使用管理控制台。
来源: http ://windowssecrets.com/top-story/certificate-cleanup-for-most-personal-computers/
| 归档时间: |
|
| 查看次数: |
14506 次 |
| 最近记录: |