X509Certificate Class
Collapse the table of content
Expand the table of content

X509Certificate Class

 

Provides methods that help you use X.509 v.3 certificates.

Namespace:   System.Security.Cryptography.X509Certificates
Assembly:  mscorlib (in mscorlib.dll)

System.Object
  System.Security.Cryptography.X509Certificates.X509Certificate
    System.Security.Cryptography.X509Certificates.X509Certificate2

[SerializableAttribute]
[ComVisibleAttribute(true)]
public class X509Certificate : IDisposable, IDeserializationCallback, 
	ISerializable

NameDescription
System_CAPS_pubmethodX509Certificate()

Initializes a new instance of the X509Certificate class.

System_CAPS_pubmethodX509Certificate(Byte[])

Initializes a new instance of the X509Certificate class defined from a sequence of bytes representing an X.509v3 certificate.

System_CAPS_pubmethodX509Certificate(Byte[], SecureString)

Initializes a new instance of the X509Certificate class using a byte array and a password.

System_CAPS_pubmethodX509Certificate(Byte[], SecureString, X509KeyStorageFlags)

Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.

System_CAPS_pubmethodX509Certificate(Byte[], String)

Initializes a new instance of the X509Certificate class using a byte array and a password.

System_CAPS_pubmethodX509Certificate(Byte[], String, X509KeyStorageFlags)

Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.

System_CAPS_pubmethodX509Certificate(IntPtr)

Initializes a new instance of the X509Certificate class using a handle to an unmanaged PCCERT_CONTEXT structure.

System_CAPS_pubmethodX509Certificate(SerializationInfo, StreamingContext)

Initializes a new instance of the X509Certificate class using a SerializationInfo object and a StreamingContext structure.

System_CAPS_pubmethodX509Certificate(String)

Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file.

System_CAPS_pubmethodX509Certificate(String, SecureString)

Initializes a new instance of the X509Certificate class using a certificate file name and a password.

System_CAPS_pubmethodX509Certificate(String, SecureString, X509KeyStorageFlags)

Initializes a new instance of the X509Certificate class using a certificate file name, a password, and a key storage flag.

System_CAPS_pubmethodX509Certificate(String, String)

Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file and a password to access the certificate.

System_CAPS_pubmethodX509Certificate(String, String, X509KeyStorageFlags)

Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file, a password to access the certificate, and a key storage flag.

System_CAPS_pubmethodX509Certificate(X509Certificate)

Initializes a new instance of the X509Certificate class using another X509Certificate class.

NameDescription
System_CAPS_pubpropertyHandle

Gets a handle to a Microsoft Cryptographic API certificate context described by an unmanaged PCCERT_CONTEXT structure.

System_CAPS_pubpropertyIssuer

Gets the name of the certificate authority that issued the X.509v3 certificate.

System_CAPS_pubpropertySubject

Gets the subject distinguished name from the certificate.

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCreateFromCertFile(String)

Creates an X.509v3 certificate from the specified PKCS7 signed file.

System_CAPS_pubmethodSystem_CAPS_staticCreateFromSignedFile(String)

Creates an X.509v3 certificate from the specified signed file.

System_CAPS_pubmethodDispose()

Releases all resources used by the current X509Certificate object.

System_CAPS_protmethodDispose(Boolean)

Releases all of the unmanaged resources used by this X509Certificate and optionally releases the managed resources.

System_CAPS_pubmethodEquals(Object)

Compares two X509Certificate objects for equality.(Overrides Object.Equals(Object).)

System_CAPS_pubmethodEquals(X509Certificate)

Compares two X509Certificate objects for equality.

System_CAPS_pubmethodExport(X509ContentType)

Exports the current X509Certificate object to a byte array in a format described by one of the X509ContentType values.

System_CAPS_pubmethodExport(X509ContentType, SecureString)

Exports the current X509Certificate object to a byte array using the specified format and a password.

System_CAPS_pubmethodExport(X509ContentType, String)

Exports the current X509Certificate object to a byte array in a format described by one of the X509ContentType values, and using the specified password.

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_protmethodSystem_CAPS_staticFormatDate(DateTime)

Converts the specified date and time to a string.

System_CAPS_pubmethodGetCertHash()

Returns the hash value for the X.509v3 certificate as an array of bytes.

System_CAPS_pubmethodGetCertHashString()

Returns the SHA1 hash value for the X.509v3 certificate as a hexadecimal string.

System_CAPS_pubmethodGetEffectiveDateString()

Returns the effective date of this X.509v3 certificate.

System_CAPS_pubmethodGetExpirationDateString()

Returns the expiration date of this X.509v3 certificate.

System_CAPS_pubmethodGetFormat()

Returns the name of the format of this X.509v3 certificate.

System_CAPS_pubmethodGetHashCode()

Returns the hash code for the X.509v3 certificate as an integer.(Overrides Object.GetHashCode().)

System_CAPS_pubmethodGetIssuerName()

Obsolete.Returns the name of the certification authority that issued the X.509v3 certificate.

System_CAPS_pubmethodGetKeyAlgorithm()

Returns the key algorithm information for this X.509v3 certificate as a string.

System_CAPS_pubmethodGetKeyAlgorithmParameters()

Returns the key algorithm parameters for the X.509v3 certificate as an array of bytes.

System_CAPS_pubmethodGetKeyAlgorithmParametersString()

Returns the key algorithm parameters for the X.509v3 certificate as a hexadecimal string.

System_CAPS_pubmethodGetName()

Obsolete.Returns the name of the principal to which the certificate was issued.

System_CAPS_pubmethodGetPublicKey()

Returns the public key for the X.509v3 certificate as an array of bytes.

System_CAPS_pubmethodGetPublicKeyString()

Returns the public key for the X.509v3 certificate as a hexadecimal string.

System_CAPS_pubmethodGetRawCertData()

Returns the raw data for the entire X.509v3 certificate as an array of bytes.

System_CAPS_pubmethodGetRawCertDataString()

Returns the raw data for the entire X.509v3 certificate as a hexadecimal string.

System_CAPS_pubmethodGetSerialNumber()

Returns the serial number of the X.509v3 certificate as an array of bytes.

System_CAPS_pubmethodGetSerialNumberString()

Returns the serial number of the X.509v3 certificate as a hexadecimal string.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodImport(Byte[])

Populates the X509Certificate object with data from a byte array.

System_CAPS_pubmethodImport(Byte[], SecureString, X509KeyStorageFlags)

Populates an X509Certificate object using data from a byte array, a password, and a key storage flag.

System_CAPS_pubmethodImport(Byte[], String, X509KeyStorageFlags)

Populates the X509Certificate object using data from a byte array, a password, and flags for determining how the private key is imported.

System_CAPS_pubmethodImport(String)

Populates the X509Certificate object with information from a certificate file.

System_CAPS_pubmethodImport(String, SecureString, X509KeyStorageFlags)

Populates an X509Certificate object with information from a certificate file, a password, and a key storage flag.

System_CAPS_pubmethodImport(String, String, X509KeyStorageFlags)

Populates the X509Certificate object with information from a certificate file, a password, and a X509KeyStorageFlags value.

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodReset()

Resets the state of the X509Certificate2 object.

System_CAPS_pubmethodToString()

Returns a string representation of the current X509Certificate object.(Overrides Object.ToString().)

System_CAPS_pubmethodToString(Boolean)

Returns a string representation of the current X509Certificate object, with extra information, if specified.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIDeserializationCallback.OnDeserialization(Object)

Implements the ISerializable interface and is called back by the deserialization event when deserialization is complete.

System_CAPS_pubinterfaceSystem_CAPS_privmethodISerializable.GetObjectData(SerializationInfo, StreamingContext)

Gets serialization information with all the data needed to recreate an instance of the current X509Certificate object.

ASN.1 DER is the only certificate format supported by this class.

For most scenarios, you should use the X509Certificate2 class instead.

System_CAPS_importantImportant

Starting with the .NET Framework 4.6, this type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

For apps that target the .NET Framework 4.5.2 and earlier versions, the X509Certificate class does not implement the IDisposable interface and therefore does not have a Dispose method.

The following example loads an X.509 certificate from a file, calls the ToString method, and displays the results to the console.

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


public class X509
{

    public static void Main()
    {

        // The path to the certificate.
        string Certificate = "Certificate.cer";

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = new X509Certificate(Certificate);

        // Get the value.
        string resultsTrue = cert.ToString(true);

        // Display the value to the console.
        Console.WriteLine(resultsTrue);

        // Get the value.
        string resultsFalse = cert.ToString(false);

        // Display the value to the console.
        Console.WriteLine(resultsFalse);

    }

}

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft