X509Store Class
Represents an X.509 store, which is a physical store where certificates are persisted and managed. This class cannot be inherited.
Assembly: System (in System.dll)
The X509Store type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | X509Store | Initializes a new instance of the X509Store class using the personal certificates of the current user store. |
![]() | X509Store(IntPtr) | Initializes a new instance of the X509Store class using an Intptr handle to an HCERTSTORE store. |
![]() | X509Store(StoreLocation) | Initializes a new instance of the X509Store class using the specified StoreLocation value. |
![]() | X509Store(StoreName) | Initializes a new instance of the X509Store class using the specified StoreName value. |
![]() | X509Store(String) | Initializes a new instance of the X509Store class using the specified store name. |
![]() | X509Store(StoreName, StoreLocation) | Initializes a new instance of the X509Store class using the specified StoreName and StoreLocation values. |
![]() | X509Store(String, StoreLocation) | Initializes a new instance of the X509Store class using a string that represents a value from the StoreName enumeration and a value from the StoreLocation enumeration. |
| Name | Description | |
|---|---|---|
![]() | Certificates | Returns a collection of certificates located in an X.509 certificate store. |
![]() | Location | Gets the location of the X.509 certificate store. |
![]() | Name | Gets the name of the X.509 certificate store. |
![]() | StoreHandle | Gets an IntPtr handle to an HCERTSTORE store. |
| Name | Description | |
|---|---|---|
![]() | Add | Adds a certificate to an X.509 certificate store. |
![]() | AddRange | Adds a collection of certificates to an X.509 certificate store. |
![]() | Close | Closes an X.509 certificate store. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | Open | Opens an X.509 certificate store or creates a new store, depending on OpenFlags flag settings. |
![]() | Remove | Removes a certificate from an X.509 certificate store. |
![]() | RemoveRange | Removes a range of certificates from an X.509 certificate store. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The following code example opens an X.509 certificate store, adds and deletes certificates, and then closes the store. It assumes that you have three certificates to add to and remove from a local store.
Imports System Imports System.Security.Cryptography Imports System.Security.Cryptography.X509Certificates Imports System.IO Class X509store2 Shared Sub Main(ByVal args() As String) 'Create new X509 store called teststore from the local certificate store. Dim store As New X509Store("teststore", StoreLocation.CurrentUser) store.Open(OpenFlags.ReadWrite) Dim certificate As New X509Certificate2() 'Create certificates from certificate files. 'You must put in a valid path to three certificates in the following constructors. Dim certificate1 As New X509Certificate2("c:\mycerts\*****.cer") Dim certificate2 As New X509Certificate2("c:\mycerts\*****.cer") Dim certificate5 As New X509Certificate2("c:\mycerts\*****.cer") 'Create a collection and add two of the certificates. Dim collection As New X509Certificate2Collection() collection.Add(certificate2) collection.Add(certificate5) 'Add certificates to the store. store.Add(certificate1) store.AddRange(collection) Dim storecollection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection) Console.WriteLine("Store name: {0}", store.Name) Console.WriteLine("Store location: {0}", store.Location) Dim x509 As X509Certificate2 For Each x509 In storecollection Console.WriteLine("certificate name: {0}", x509.Subject) Next x509 'Remove a certificate. store.Remove(certificate1) Dim storecollection2 As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection) Console.WriteLine("{1}Store name: {0}", store.Name, Environment.NewLine) Dim x509a As X509Certificate2 For Each x509a In storecollection2 Console.WriteLine("certificate name: {0}", x509a.Subject) Next x509a 'Remove a range of certificates. store.RemoveRange(collection) Dim storecollection3 As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection) Console.WriteLine("{1}Store name: {0}", store.Name, Environment.NewLine) If storecollection3.Count = 0 Then Console.WriteLine("Store contains no certificates.") Else Dim x509b As X509Certificate2 For Each x509b In storecollection3 Console.WriteLine("certificate name: {0}", x509b.Subject) Next x509b End If 'Close the store. store.Close() End Sub End Class
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.


