安全なアプリケーションの場合、ダイアログで証明書を選択する必要があります。C#を使用して証明書ストアまたはその一部(storeLocation="Local Machine"
およびなど)にアクセスし、そこからすべての証明書のコレクションを取得するにはどうすればよいですか?storeName="My"
よろしくお願いします。
111224 次
5 に答える
75
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 certificate in store.Certificates){
//TODO's
}
于 2011-05-17T08:46:21.627 に答える
20
これを試して:
//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;
}
于 2011-07-26T13:25:40.860 に答える
11
The simplest way to do that is by opening the certificate store you want and then using X509Certificate2UI
.
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var selectedCertificate = X509Certificate2UI.SelectFromCollection(
store.Certificates,
"Title",
"MSG",
X509SelectionFlag.SingleSelection);
More information in X509Certificate2UI
on MSDN.
于 2015-03-15T14:21:02.417 に答える
4
はい --X509Store.Certificates
プロパティは X.509 証明書ストアのスナップショットを返します。
于 2009-07-30T09:00:19.930 に答える