public sealed class X509Certificate
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.
public string Issuer { get; }
public string IssuerName { get; }
public DateTime NotAfter { get; }
public DateTime NotBefore { get; }
public System.Security.Cryptography.AsymmetricAlgorithm PublicKey { get; }
public string Subject { get; }
public string SubjectName { get; }
public override bool Equals(object obj);
public byte[] GetCertHash();
public string GetCertHashString();
public string GetExtensionValue(string oid);
oid: The Object Identifier (OID) of the extension.
public string GetFormat();
public string GetKeyAlgorithm();
public string GetKeyAlgorithmParameters();
public string GetPublicKeyString();
public byte[] GetRawCertData();
public string GetRawCertDataString();
public string GetSerialNumber();
public byte[] GetSignature();
public string GetSignatureHashAlgorithm();
public System.Security.Cryptography.X509Certificates.X509Store GetStore();
public override string ToString();
public string ToString(bool fhtml);
fhtml: true to format the output as HTML; otherwise, false.
X509Certificate class.public X509Certificate();
X509Certificate class using the specified array of bytes.public X509Certificate(byte[] data);
data: A byte array containing the X.509 certificate.
X509Certificate class using the specified file.public X509Certificate(string fileName);
fileName: The path to the certificate file.
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.
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);
}
}