System.Net.Security.CertificateStoreName Enumeration

Specifies the names of certificate stores.

Syntax

public enum CertificateStoreName

Remarks

The CertificateStoreName enumeration is used to specify the target certificate store when performing operations such as retrieving or adding certificates. These store names are standard Windows certificate store names.

When working with the X509Certificate2Collection or related classes, you can often specify the store to query or modify.

Members

Name Description
AddressBook The AddressBook store.
AuthRoot The AuthRoot store.
CertificateAuthority The CertificateAuthority store.
Disallowed The Disallowed store.
My The My store (personal certificates).
Root The Root store (trusted root certification authorities).
TrustedPublisher The TrustedPublisher store.

Requirements

Namespace:  System.Net.Security
Assembly:  System (in System.dll)
Platform:  Windows

See Also

Example

The following example demonstrates how to retrieve all personal certificates from the "My" store.

using System;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

public class CertificateExample
{
    public static void Main(string[] args)
    {
        try
        {
            X509Store store = new X509Store(CertificateStoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly);

            X509Certificate2Collection certificates = store.Certificates;

            Console.WriteLine($"Found {certificates.Count} certificates in the My store:");

            foreach (X509Certificate2 cert in certificates)
            {
                Console.WriteLine($"- {cert.SubjectName.Name}");
            }

            store.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}