[英]C# list installed certificates
首先,我是 C# 的完全新手,所以我只是在網上搜索可能性 我想得到什么: 我想要一個按鈕,用於檢索個人商店中已安裝證書的列表。
我已經嘗試了一點,但是收到有關缺少引用等的消息。所以我希望有人能給我一些如何實現這一點的建議。
我在網上找到的是:
using System.Security.Cryptography.X509Certificates;
public static X509Certificate2 selectCert(StoreName store, StoreLocation location, string windowTitle, string windowMsg)
{
X509Certificate2 certSelected = null;
X509Store x509Store = new X509Store(store, location);
x509Store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col = x509Store.Certificates;
X509Certificate2Collection sel = X509Certificate2UI.SelectFromCollection(col, windowTitle, windowMsg, X509SelectionFlag.SingleSelection);
if (sel.Count > 0)
{
X509Certificate2Enumerator en = sel.GetEnumerator();
en.MoveNext();
certSelected = en.Current;
}
x509Store.Close();
return certSelected;
}
你的
(我使用視覺工作室...)
添加對System.Security.dll
的引用以使用X509Certificate2UI類。
你可以使用 foreach
if (sel.Count > 0){
foreach(var cert in sel){
certSelected = cert ;
}
}
using System.Linq;
...
if (sel.Count > 0){
return sel.FirstOrDefault();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.