Export (0) Print
Expand All

X509Certificate Class

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

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

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

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

The X509Certificate type exposes the following members.

  NameDescription
Public methodX509Certificate()Initializes a new instance of the X509Certificate class.
Public methodX509Certificate(Byte[])Initializes a new instance of the X509Certificate class defined from a sequence of bytes representing an X.509v3 certificate.
Public methodX509Certificate(IntPtr)Initializes a new instance of the X509Certificate class using a handle to an unmanaged PCCERT_CONTEXT structure.
Public methodX509Certificate(String)Initializes a new instance of the X509Certificate class using the name of a PKCS7 signed file.
Public methodX509Certificate(X509Certificate)Initializes a new instance of the X509Certificate class using another X509Certificate class.
Public methodX509Certificate(Byte[], SecureString)Initializes a new instance of the X509Certificate class using a byte array and a password.
Public methodX509Certificate(Byte[], String)Initializes a new instance of the X509Certificate class using a byte array and a password.
Public methodX509Certificate(SerializationInfo, StreamingContext)Initializes a new instance of the X509Certificate class using a SerializationInfo object and a StreamingContext structure.
Public methodX509Certificate(String, SecureString)Initializes a new instance of the X509Certificate class using a certificate file name and a password.
Public methodX509Certificate(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.
Public methodX509Certificate(Byte[], SecureString, X509KeyStorageFlags)Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.
Public methodX509Certificate(Byte[], String, X509KeyStorageFlags)Initializes a new instance of the X509Certificate class using a byte array, a password, and a key storage flag.
Public methodX509Certificate(String, SecureString, X509KeyStorageFlags)Initializes a new instance of the X509Certificate class using a certificate file name, a password, and a key storage flag.
Public methodX509Certificate(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.
Top

  NameDescription
Public propertyHandleGets a handle to a Microsoft Cryptographic API certificate context described by an unmanaged PCCERT_CONTEXT structure.
Public propertyIssuerGets the name of the certificate authority that issued the X.509v3 certificate.
Public propertySubjectGets the subject distinguished name from the certificate.
Top

  NameDescription
Public methodStatic memberCreateFromCertFileCreates an X.509v3 certificate from the specified PKCS7 signed file.
Public methodStatic memberCreateFromSignedFileCreates an X.509v3 certificate from the specified signed file.
Public methodEquals(Object)Compares two X509Certificate objects for equality. (Overrides Object.Equals(Object).)
Public methodEquals(X509Certificate)Compares two X509Certificate objects for equality.
Public methodExport(X509ContentType)Exports the current X509Certificate object to a byte array in a format described by one of the X509ContentType values.
Public methodExport(X509ContentType, SecureString)Exports the current X509Certificate object to a byte array using the specified format and a password.
Public methodExport(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.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected methodStatic memberFormatDateConverts the specified date and time to a string.
Public methodGetCertHashReturns the hash value for the X.509v3 certificate as an array of bytes.
Public methodGetCertHashStringReturns the SHA1 hash value for the X.509v3 certificate as a hexadecimal string.
Public methodGetEffectiveDateStringReturns the effective date of this X.509v3 certificate.
Public methodGetExpirationDateStringReturns the expiration date of this X.509v3 certificate.
Public methodGetFormatReturns the name of the format of this X.509v3 certificate.
Public methodGetHashCodeReturns the hash code for the X.509v3 certificate as an integer. (Overrides Object.GetHashCode().)
Public methodGetIssuerName Obsolete. Returns the name of the certification authority that issued the X.509v3 certificate.
Public methodGetKeyAlgorithmReturns the key algorithm information for this X.509v3 certificate.
Public methodGetKeyAlgorithmParametersReturns the key algorithm parameters for the X.509v3 certificate.
Public methodGetKeyAlgorithmParametersStringReturns the key algorithm parameters for the X.509v3 certificate.
Public methodGetName Obsolete. Returns the name of the principal to which the certificate was issued.
Public methodGetPublicKeyReturns the public key for the X.509v3 certificate.
Public methodGetPublicKeyStringReturns the public key for the X.509v3 certificate.
Public methodGetRawCertDataReturns the raw data for the entire X.509v3 certificate.
Public methodGetRawCertDataStringReturns the raw data for the entire X.509v3 certificate.
Public methodGetSerialNumberReturns the serial number of the X.509v3 certificate.
Public methodGetSerialNumberStringReturns the serial number of the X.509v3 certificate.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodImport(Byte[])Populates the X509Certificate object with data from a byte array.
Public methodImport(String)Populates the X509Certificate object with information from a certificate file.
Public methodImport(Byte[], SecureString, X509KeyStorageFlags)Populates an X509Certificate object using data from a byte array, a password, and a key storage flag.
Public methodImport(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.
Public methodImport(String, SecureString, X509KeyStorageFlags)Populates an X509Certificate object with information from a certificate file, a password, and a key storage flag.
Public methodImport(String, String, X509KeyStorageFlags)Populates the X509Certificate object with information from a certificate file, a password, and a X509KeyStorageFlags value.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodResetResets the state of the X509Certificate2 object.
Public methodToString()Returns a string representation of the current X509Certificate object. (Overrides Object.ToString().)
Public methodToString(Boolean)Returns a string representation of the current X509Certificate object, with extra information, if specified.
Top

  NameDescription
Explicit interface implemetationPrivate methodIDeserializationCallback.OnDeserializationImplements the ISerializable interface and is called back by the deserialization event when deserialization is complete.
Explicit interface implemetationPrivate methodISerializable.GetObjectDataGets serialization information with all the data needed to recreate an instance of the current X509Certificate object.
Top

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

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

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);

    }

}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

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

Community Additions

ADD
Show:
© 2014 Microsoft