X509SelectionFlag 枚举

定义

指定使用 SelectFromCollection 方法请求的选择类型。

public enum class X509SelectionFlag
public enum X509SelectionFlag
type X509SelectionFlag = 
Public Enum X509SelectionFlag
继承
X509SelectionFlag

字段

MultiSelection 1

多重选择。 用户可以使用 Shift 或 Ctrl 键选择多个 X.509 证书。

SingleSelection 0

单项选择。 该用户界面允许用户选择一个 X.509 证书。

示例

下面的代码示例演示如何将选择标志与 方法一起使用 X509Certificate2UI.SelectFromCollection 。 此代码示例是为 X509Store 类提供的一个更大示例的一部分。 更大的示例打开当前用户的个人证书存储,允许用户选择证书,然后将证书和证书链信息写入控制台。 输出取决于用户选择的证书。

//Create new X509 store from local certificate store.
X509Store ^ store = gcnew X509Store( "MY",StoreLocation::CurrentUser );
store->Open( static_cast<OpenFlags>(OpenFlags::OpenExistingOnly | OpenFlags::ReadWrite) );

//Output store information.
Console::WriteLine( "Store Information" );
Console::WriteLine( "Number of certificates in the store: {0}", store->Certificates->Count );
Console::WriteLine( "Store location: {0}", store->Location );
Console::WriteLine( "Store name: {0} {1}", store->Name, Environment::NewLine );

//Put certificates from the store into a collection so user can select one.
X509Certificate2Collection ^ fcollection = dynamic_cast<X509Certificate2Collection^>(store->Certificates);
X509Certificate2Collection ^ collection = X509Certificate2UI::SelectFromCollection(fcollection, "Select an X509 Certificate","Choose a certificate to examine.",X509SelectionFlag::SingleSelection);
X509Certificate2 ^ certificate = collection[ 0 ];
X509Certificate2UI::DisplayCertificate(certificate);
    //Create new X509 store from local certificate store.
    X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
    store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);

    //Output store information.
    Console.WriteLine ("Store Information");
    Console.WriteLine ("Number of certificates in the store: {0}", store.Certificates.Count);
    Console.WriteLine ("Store location: {0}", store.Location);
    Console.WriteLine ("Store name: {0} {1}", store.Name, Environment.NewLine);

    //Put certificates from the store into a collection so user can select one.
    X509Certificate2Collection fcollection = (X509Certificate2Collection)store.Certificates;
    X509Certificate2Collection collection = X509Certificate2UI.SelectFromCollection(fcollection, "Select an X509 Certificate", "Choose a certificate to examine.", X509SelectionFlag.SingleSelection);
    X509Certificate2 certificate = collection[0];
    X509Certificate2UI.DisplayCertificate(certificate);
'Create new X509 store from local certificate store.
Dim store As New X509Store("MY", StoreLocation.CurrentUser)
store.Open(OpenFlags.OpenExistingOnly Or OpenFlags.ReadWrite)

'Output store information.
Console.WriteLine("Store Information")
Console.WriteLine("Number of certificates in the store: {0}", store.Certificates.Count)
Console.WriteLine("Store location: {0}", store.Location)
Console.WriteLine("Store name: {0} {1}", store.Name, Environment.NewLine)

'Put certificates from the store into a collection so user can select one.
Dim fcollection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection)
Dim collection As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(fcollection, "Select an X509 Certificate", "Choose a certificate to examine.", X509SelectionFlag.SingleSelection)
Dim certificate As X509Certificate2 = collection(0)
X509Certificate2UI.DisplayCertificate(certificate)

注解

此标志表示使用 X509Certificate2UI.SelectFromCollection 方法选择的一个或多个证书。

适用于