Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Security.​Cryptography.​X509Certificates.​X509Certificate

Assembly: System.Security.Cryptography

Inheritance: object → X509Certificate

Implemented Interfaces

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

Properties

public nint
Handle
Gets a handle to a Microsoft Cryptographic API certificate context described by an unmanaged <see langword="PCCERT_CONTEXT" /> structure.
public string
Issuer
Gets the name of the certificate authority that issued the X.509v3 certificate.
public ReadOnlyMemory<​byte>
SerialNumberBytes
Gets the big-endian representation of the certificate's serial number.
public string
Subject
Gets the subject distinguished name from the certificate.

Methods

public static X509Certificate
CreateFromCertFile​(string filename)
Creates an X.509v3 certificate from the specified PKCS7 signed file.
Returns The newly created X.509 certificate.
filename The path of the PKCS7 signed file from which to create the X.509 certificate.
public static X509Certificate
CreateFromSignedFile​(string filename)
Creates an X.509v3 certificate from the specified signed file.
Returns The newly created X.509 certificate.
filename The path of the signed file from which to create the X.509 certificate.
public void
Dispose​()
Releases all resources used by the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object.
protected void
Dispose​(bool disposing)
Releases all of the unmanaged resources used by this <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> and optionally releases the managed resources.
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
public bool
Equals​(object obj)
Compares two <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> objects for equality.
Returns <see langword="true" /> if the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object is equal to the object specified by the <paramref name="obj" /> parameter; otherwise, <see langword="false" /> .
obj An <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object to compare to the current object.
public bool
Equals​(X509Certificate other)
Compares two <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> objects for equality.
Returns <see langword="true" /> if the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object is equal to the object specified by the <paramref name="other" /> parameter; otherwise, <see langword="false" /> .
other An <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object to compare to the current object.
public byte[]
Export​(X509ContentType contentType)
Exports the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object to a byte array in a format described by one of the <see cref="T:System.Security.Cryptography.X509Certificates.X509ContentType" /> values.
Returns An array of bytes that represents the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object.
contentType One of the <see cref="T:System.Security.Cryptography.X509Certificates.X509ContentType" /> values that describes how to format the output data.
public byte[]
Export​(X509ContentType contentType, SecureString? password)
Exports the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object to a byte array using the specified format and a password.
Returns A byte array that represents the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object.
contentType One of the <see cref="T:System.Security.Cryptography.X509Certificates.X509ContentType" /> values that describes how to format the output data.
password The password required to access the X.509 certificate data.
public byte[]
Export​(X509ContentType contentType, string password)
Exports the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object to a byte array in a format described by one of the <see cref="T:System.Security.Cryptography.X509Certificates.X509ContentType" /> values, and using the specified password.
Returns An array of bytes that represents the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object.
contentType One of the <see cref="T:System.Security.Cryptography.X509Certificates.X509ContentType" /> values that describes how to format the output data.
password The password required to access the X.509 certificate data.
public byte[]
ExportPkcs12​(PbeParameters exportParameters, string password)
Exports the certificate and private key in PKCS#12 / PFX format.
Returns A byte array containing the encoded PKCS#12.
exportParameters The algorithm parameters to use for the export.
password The password to use for the export.
public byte[]
ExportPkcs12​(Pkcs12ExportPbeParameters exportParameters, string password)
Exports the certificate and private key in PKCS#12 / PFX format.
Returns A byte array containing the encoded PKCS#12.
exportParameters The algorithm parameters to use for the export.
password The password to use for the export.
protected static string
FormatDate​(DateTime date)
Converts the specified date and time to a string.
Returns A string representation of the value of the <see cref="T:System.DateTime" /> object.
date The date and time to convert.
public byte[]
GetCertHash​()
Returns the hash value for the X.509v3 certificate as an array of bytes.
Returns The hash value for the X.509 certificate.
public byte[]
GetCertHash​(HashAlgorithmName hashAlgorithm)
Returns the hash value for the X.509v3 certificate that is computed by using the specified cryptographic hash algorithm.
Returns A byte array that contains the hash value for the X.509 certificate.
hashAlgorithm The name of the cryptographic hash algorithm to use.
public string
GetCertHashString​()
Returns the SHA-1 hash value for the X.509v3 certificate as a hexadecimal string.
Returns The hexadecimal string representation of the X.509 certificate hash value.
public string
GetCertHashString​(HashAlgorithmName hashAlgorithm)
Returns a hexadecimal string containing the hash value for the X.509v3 certificate computed using the specified cryptographic hash algorithm.
Returns The hexadecimal string representation of the X.509 certificate hash value.
hashAlgorithm The name of the cryptographic hash algorithm to use.
public string
GetEffectiveDateString​()
Returns the effective date of this X.509v3 certificate.
Returns The effective date for this X.509 certificate.
public string
GetExpirationDateString​()
Returns the expiration date of this X.509v3 certificate.
Returns The expiration date for this X.509 certificate.
public string
GetFormat​()
Returns the name of the format of this X.509v3 certificate.
Returns The format of this X.509 certificate.
public int
GetHashCode​()
Returns the hash code for the X.509v3 certificate as an integer.
Returns The hash code for the X.509 certificate as an integer.
public string
GetIssuerName​()
Returns the name of the certification authority that issued the X.509v3 certificate.
Returns The name of the certification authority that issued the X.509 certificate.
public string
GetKeyAlgorithm​()
Returns the key algorithm information for this X.509v3 certificate as a string.
Returns The key algorithm information for this X.509 certificate as a string.
public byte[]
GetKeyAlgorithmParameters​()
Returns the key algorithm parameters for the X.509v3 certificate as an array of bytes.
Returns The key algorithm parameters for the X.509 certificate as an array of bytes.
public string
GetKeyAlgorithmParametersString​()
Returns the key algorithm parameters for the X.509v3 certificate as a hexadecimal string.
Returns The key algorithm parameters for the X.509 certificate as a hexadecimal string.
public string
GetName​()
Returns the name of the principal to which the certificate was issued.
Returns The name of the principal to which the certificate was issued.
public byte[]
GetPublicKey​()
Returns the public key for the X.509v3 certificate as an array of bytes.
Returns The public key for the X.509 certificate as an array of bytes.
public string
GetPublicKeyString​()
Returns the public key for the X.509v3 certificate as a hexadecimal string.
Returns The public key for the X.509 certificate as a hexadecimal string.
public byte[]
GetRawCertData​()
Returns the raw data for the entire X.509v3 certificate as an array of bytes.
Returns A byte array containing the X.509 certificate data.
public string
GetRawCertDataString​()
Returns the raw data for the entire X.509v3 certificate as a hexadecimal string.
Returns The X.509 certificate data as a hexadecimal string.
public byte[]
GetSerialNumber​()
Returns the serial number of the X.509v3 certificate as an array of bytes in little-endian order.
Returns The serial number of the X.509 certificate as an array of bytes in little-endian order.
public string
GetSerialNumberString​()
Returns the serial number of the X.509v3 certificate as a big-endian hexadecimal string.
Returns The serial number of the X.509 certificate as a big-endian hexadecimal string.
public void
Import​(byte[] rawData)
Populates the <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object with data from a byte array.
rawData A byte array containing data from an X.509 certificate.
public void
Import​(byte[] rawData, SecureString? password, X509KeyStorageFlags keyStorageFlags)
Populates an <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object using data from a byte array, a password, and a key storage flag.
rawData A byte array that contains data from an X.509 certificate.
password The password required to access the X.509 certificate data.
keyStorageFlags A bitwise combination of the enumeration values that control where and how to import the certificate.
public void
Import​(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
Populates the <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object using data from a byte array, a password, and flags for determining how the private key is imported.
rawData A byte array containing data from an X.509 certificate.
password The password required to access the X.509 certificate data.
keyStorageFlags A bitwise combination of the enumeration values that control where and how to import the certificate.
public void
Import​(string fileName)
Populates the <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object with information from a certificate file.
fileName The name of a certificate file represented as a string.
public void
Import​(string fileName, SecureString? password, X509KeyStorageFlags keyStorageFlags)
Populates an <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object with information from a certificate file, a password, and a key storage flag.
fileName The name of a certificate file.
password The password required to access the X.509 certificate data.
keyStorageFlags A bitwise combination of the enumeration values that control where and how to import the certificate.
public void
Import​(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
Populates the <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object with information from a certificate file, a password, and a <see cref="T:System.Security.Cryptography.X509Certificates.X509KeyStorageFlags" /> value.
fileName The name of a certificate file represented as a string.
password The password required to access the X.509 certificate data.
keyStorageFlags A bitwise combination of the enumeration values that control where and how to import the certificate.
public void
Reset​()
Resets the state of the <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate2" /> object.
public string
ToString​()
Returns a string representation of the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object.
Returns A string representation of the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object.
public string
ToString​(bool fVerbose)
Returns a string representation of the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object, with extra information, if specified.
Returns A string representation of the current <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate" /> object.
fVerbose <see langword="true" /> to produce the verbose form of the string representation; otherwise, <see langword="false" /> .
public bool
TryGetCertHash​(HashAlgorithmName hashAlgorithm, Span<​byte> destination, Int32& bytesWritten)
protected void
Finalize​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object