X509Certificate Class

Namespace: System.Security.Cryptography.X509Certificates
Represents an X.509 certificate. This class cannot be inherited.

Syntax

public sealed class X509Certificate

Remarks

An X.509 certificate is a digital certificate that uses the Distinguished Encoding Rules (DER) format to bind a public key to an individual or entity. X.509 certificates are used in security-enabled applications such as Secure Sockets Layer (SSL) and Transport Layer Security (TLS).

The X509Certificate class provides properties and methods to access the information contained within an X.509 certificate, such as the issuer, subject, public key, and expiration date. It also provides methods for encoding and decoding certificate data.

Properties

Issuer

Gets the issuer name of the X.509 certificate.
public string Issuer { get; }

IssuerName

Gets the issuer name of the X.509 certificate.
public string IssuerName { get; }

NotAfter

Gets the date and time after which the certificate is no longer valid.
public DateTime NotAfter { get; }

NotBefore

Gets the date and time at which the certificate becomes valid.
public DateTime NotBefore { get; }

PublicKey

Gets the public key of the X.509 certificate.
public System.Security.Cryptography.AsymmetricAlgorithm PublicKey { get; }

Subject

Gets the subject name of the X.509 certificate.
public string Subject { get; }

SubjectName

Gets the subject name of the X.509 certificate.
public string SubjectName { get; }

Methods

Equals(object obj)

Determines whether the specified object is equal to the current object.
public override bool Equals(object obj);

GetCertHash()

Returns the hash of the certificate.
public byte[] GetCertHash();

GetCertHashString()

Returns the hash of the certificate as a string.
public string GetCertHashString();

GetExtensionValue(string oid)

Retrieves the value of a certificate extension.
public string GetExtensionValue(string oid);

oid: The Object Identifier (OID) of the extension.

GetFormat()

Returns the format of the certificate.
public string GetFormat();

GetKeyAlgorithm()

Returns the public key algorithm of the certificate.
public string GetKeyAlgorithm();

GetKeyAlgorithmParameters()

Returns the parameters for the public key algorithm.
public string GetKeyAlgorithmParameters();

GetPublicKeyString()

Returns the public key of the certificate as a string.
public string GetPublicKeyString();

GetRawCertData()

Returns the raw certificate data.
public byte[] GetRawCertData();

GetRawCertDataString()

Returns the raw certificate data as a string.
public string GetRawCertDataString();

GetSerialNumber()

Returns the serial number of the X.509 certificate.
public string GetSerialNumber();

GetSignature()

Returns the signature of the X.509 certificate.
public byte[] GetSignature();

GetSignatureHashAlgorithm()

Returns the signature hash algorithm used for the X.509 certificate.
public string GetSignatureHashAlgorithm();

GetStore()

Returns the certificate store that contains this certificate.
public System.Security.Cryptography.X509Certificates.X509Store GetStore();

Getသက်oString()

Converts the value of this instance to its equivalent string representation.
public override string ToString();

ToString(bool fhtml)

Converts the value of this instance to its equivalent string representation, specifying whether to format the output as HTML.
public string ToString(bool fhtml);

fhtml: true to format the output as HTML; otherwise, false.

Constructors

X509Certificate()

Initializes a new instance of the X509Certificate class.
public X509Certificate();

X509Certificate(byte[] data)

Initializes a new instance of the X509Certificate class using the specified array of bytes.
public X509Certificate(byte[] data);

data: A byte array containing the X.509 certificate.

X509Certificate(string fileName)

Initializes a new instance of the X509Certificate class using the specified file.
public X509Certificate(string fileName);

fileName: The path to the certificate file.

X509Certificate(string fileName, string password)

Initializes a new instance of the X509Certificate class using the specified file and password.
public X509Certificate(string fileName, string password);

fileName: The path to the certificate file. password: The password for the certificate file.

Example

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

public class Example
{
    public static void Main()
    {
        // Load a certificate from a file
        X509Certificate2 cert = new X509Certificate2("mycert.pfx", "mypassword");

        Console.WriteLine("Certificate Subject: " + cert.Subject);
        Console.WriteLine("Issuer: " + cert.Issuer);
        Console.WriteLine("Valid Until: " + cert.NotAfter);
        Console.WriteLine("Public Key Algorithm: " + cert.PublicKey.Key.Algorithm);
    }
}
← X509Chain
X509Certificate2 →