CertificateStore Class
Provides the methods and properties for accessing certificate stores.
Inheritance Hierarchy
SystemObject
  MailBee.SecurityCertificateStore

Namespace: MailBee.Security
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public class CertificateStore : IDisposable

The CertificateStore type exposes the following members.

Constructors
  NameDescription
Public methodCertificateStore
Creates a new certificate store in memory.
Public methodCode exampleCertificateStore(X509Store)
Initializes CertificateStore instance from the existing X509Store object.
Public methodCertificateStore(Byte, String)
Opens an existing store of certificates from a memory footprint of a PFX (.P12, PKCS #12) file.
Public methodCertificateStore(Byte, CertStoreType, CryptoServiceProvider)
Opens an existing store of certificates from a memory footprint of a PKCS #7 (.P7B) or Serialized Certificate Storage (.SST) file.
Public methodCode exampleCertificateStore(String, CertStoreType, String)
Opens an existing or creates a new store of certificates.
Public methodCertificateStore(String, CertStoreType, String, CryptoServiceProvider, RegistryStoreLocation)
Opens an existing or creates a new store of certificates.
Top
Methods
  NameDescription
Public methodCode exampleAddCertificate
Adds the specified certificate to the store.
Public methodCode exampleAddCertificates
Adds all the certificates from the specified collection to the store.
Public methodCode exampleDeleteCertificate
Removes the specified certificate from the store.
Public methodDispose
Releases the resources associated with the current CertificateStore object.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodCode exampleFindCertificates
Searches the certificates in the store by the specified criteria.
Public methodCode exampleGetAllCertificates
Creates and returns a collection of all the certificates contained in the certificate store.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberCode exampleRegisterSystemStore
Registers a new system certificate store.
Public methodCode exampleSaveToFile
Saves the certificate store into a file.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodStatic memberCode exampleUnregisterSystemStore
Unregisters an existing system certificate store.
Top
Fields
  NameDescription
Public fieldStatic memberIntermediateCA
Gets the name of the system certificate store containing certificates of intermediate certification authorities.
Public fieldStatic memberOtherPeople
Gets the name of the system certificate store containing certificates of other entities such as your address book members.
Public fieldStatic memberPersonal
Gets the name of the system certificate store containing personal certificates.
Public fieldStatic memberRootCA
Gets the name of the system certificate store containing certificates of trusted root certification authorities.
Top
Properties
  NameDescription
Public propertyLastResult
Gets a numeric code of the last error.
Public propertyThrowExceptions
Gets or sets whether the object will throw exceptions on errors.
Top
Remarks

Certificate store is a persistent or memory storage of certificates. There are a number of types of certificate stores supported by Windows (and therefore by MailBee), listed in CertStoreType enumeration.

Stores of System type play key role in many security procedures. You can view the contents of the system stores in "Internet Options/Content/Certificates" dialog of Internet Explorer. CertificateStore class defines several constants which refer to the standard system stores (such as Personal). Also, you can create your own system stores with RegisterSystemStore(String, RegistryStoreLocation) method.

Note Note
In UWP, this class is available starting from Windows 10 Fall Creators update.
Note Note
In .NET Standard 2.0 edition, this class is a thin wrapper around X509Store. Moreover, Smime class now provides new crypto methods with "2" suffix in their names which make using CertificateStore class unnecessary.
Note Note
ASP.NET application developers should be aware that the system certificate stores of ASP.NET user may contain fewer number of certificates in comparison to those of regular users. See S/MIME Demo for ASP.NET sample project shipped with the product for more information on how to deal with this.
Examples
This sample opens the standard system store and displays the details for each certificate.
// To use the code below, import MailBee namespace at the top of your code
using MailBee.Security;

// The actual code (put it into a method of your class).
CertificateStore store = new CertificateStore(CertificateStore.Personal, CertStoreType.System, null);
CertificateCollection coll = store.GetAllCertificates();

foreach (Certificate cert in coll)
{
    Console.WriteLine("Issued to: " + cert.IssuedTo);
    Console.WriteLine("Issued by: " + cert.IssuedBy);
    Console.WriteLine("Email: " + cert.EmailAddress);
    Console.WriteLine("Valid to: " + cert.ValidToDate);
    Console.WriteLine("Has private key: " + cert.HasPrivateKey);
    Console.WriteLine("------------------------------");
}
See Also