Certificate Class
Provides methods and properties for accessing a digital certificate.
Inheritance Hierarchy
SystemObject
  MailBee.SecurityCertificate

Namespace: MailBee.Security
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public class Certificate : IDisposable

The Certificate type exposes the following members.

Constructors
  NameDescription
Public methodCertificate(X509Certificate2)
Initializes certificate from X509Certificate2 object.
Public methodCertificate(Byte, CertFileType, String)
Loads the certificate from binary data and returns it as Certificate object.
Public methodCertificate(String, CertFileType, String)
Loads the certificate from a file and returns it as Certificate object.
Top
Methods
  NameDescription
Public methodDispose
Releases the resources associated with the Certificate 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 methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberLoadFromFileAsync
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSaveToFile
Saves the certificate into a file on disk.
Public methodSaveToFileAsync
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodCode exampleValidate
Checks if the certificate is valid.
Public methodValidate(X509Certificate2Collection)
Checks if the certificate is valid.
Public methodValidate(CertificateStore)
Checks if the certificate is valid.
Top
Properties
  NameDescription
Public propertyAsX509Certificate
Gets the certificate as X509Certificate2 object.
Public propertyCode exampleEmailAddress
Gets the e-mail address of the certificate principal.
Public propertyCode exampleHasPrivateKey
Gets whether the certificate has a private key.
Public propertyCode exampleIssuedBy
Gets the name of the certification authority that issued the X.509 certificate.
Public propertyCode exampleIssuedTo
Gets the name of the entity this certificate was issued to.
Public propertyCode exampleIssuerDetails
Gets the name of the certification authority which issued this X.509 certificate.
Public propertyCode exampleKeyAlgorithmString
Gets a string containing OID of algorithm used to generate a public key of X.509 certificate.
Public propertyLastResult
Gets a numeric code of the last error.
Public propertyCode exampleName
Gets the details about the principal to which the certificate was issued.
Public propertyPublicKey
Gets a public key for X.509 certificate as a byte array.
Public propertyCode examplePublicKeyString
Gets a string containing a public key for X.509 certificate.
Public propertyCode exampleRawData
Gets the raw X.509 certificate data as a byte array.
Public propertySerialNumber
Gets the serial number of the X.509-formatted certificate as a byte array.
Public propertyCode exampleSerialNumberString
Gets the serial number of the X.509-formatted certificate as a string.
Public propertyCode exampleSignatureAlgorithm
Gets the information about cryptographic algorithm used to sign the certificate.
Public propertyCode exampleSubject
Gets the subject of X.509 certificate.
Public propertySubjectAlternativeName
Gets the subject's alternative name of X.509 certificate.
Public propertyThrowExceptions
Gets or sets whether the object will throw exceptions on errors.
Public propertyThumbprint
Gets the thumbprint of a certificate.
Public propertyCode exampleValidFromDate
Gets the date the certificate is valid from.
Public propertyCode exampleValidToDate
Gets the date the certificate certificate is no longer valid from.
Top
Remarks

Certificate class represents a digital certificate in MailBee.

Digital certificate is a statement which uses a digital signature to bind together a public key of an entity with information about this entity. After the trusted organization (also called a certification authority, CA) has verified the entity, it issues the requested certificate to the entity.

Certificates can contain different types of data, such as the serial number of the certificate, the algorithm used to sign the certificate, the name of the CA that issued the certificate, the name and public key of the entity requesting the certificate, and the CA's signature.

EmailAddress and HasPrivateKey are the most important properties of the certificate.

Note Note
To use this class, make sure MailBee.NET Security is licensed (MailBee.NET Objects full bundle does include the license).
Note Note
Starting from .NET Standard 2.0 edition (e.g. .NET Core 2.0 and newer), it's recommended to use system-provided X509Certificate2 and X509Certificate2Collection classes directly. The only case when you'll need Certificate or CertificateCollection is calling SignAndEncrypt(MailMessage, Certificate, CertificateCollection) method. You can use Certificate(X509Certificate2) and FromX509Certificate2Collection(X509Certificate2Collection) methods to wrap X509Certificate2 and X509Certificate2Collection objects with their MailBee counterparts.
Examples
This sample loads the certificate from the specified file and displays its fields.
// 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).
Certificate cert = new Certificate(@"C:\Temp\certificate.cer", CertFileType.Cer, null);

Console.WriteLine("Email address: " + cert.EmailAddress);
Console.WriteLine("Private key available: " + cert.HasPrivateKey);
Console.WriteLine("Issued by: " + cert.IssuedBy);
Console.WriteLine("Issued to: " + cert.IssuedTo);
Console.WriteLine("Issuer: " + cert.IssuedBy);
Console.WriteLine("Key algorithm: " + cert.KeyAlgorithmString);
Console.WriteLine("Name: " + cert.Name);
Console.WriteLine("Public key: " + cert.PublicKeyString);
Console.WriteLine("Serial number: " + cert.SerialNumberString);
Console.WriteLine("Subject: " + cert.Subject);
Console.WriteLine("Valid from " + cert.ValidFromDate + " till " + cert.ValidToDate);
See Also