public string SerialNumber { get; }
The SerialNumber property gets the serial number of the X.509 certificate.
The serial number is a string representation of the certificate's serial number, typically in hexadecimal format.
A string that contains the serial number of the certificate.
The following example displays the serial number of a certificate.
using System;
using System.Security.Cryptography.X509Certificates;
public class Example
{
public static void Main(string[] args)
{
try
{
// Load a certificate from the CurrentUser's My store
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = store.Certificates;
if (certCollection.Count > 0)
{
X509Certificate2 cert = certCollection[0]; // Get the first certificate
Console.WriteLine($"Certificate Subject: {cert.Subject}");
Console.WriteLine($"Serial Number: {cert.SerialNumber}");
}
else
{
Console.WriteLine("No certificates found in the CurrentUser's My store.");
}
store.Close();
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}