X509Certificate2.Thumbprint Property
Gets the thumbprint of the certificate.
Property Value
A string that contains the thumbprint of the certificate. The thumbprint is a unique identifier for the certificate.
Remarks
The thumbprint is a hash of the certificate's public key information. It is used to uniquely identify a certificate within a certificate store. The thumbprint is returned as a hexadecimal string without any separators.
For example, a thumbprint might look like: "0000000000000000000000000000000000000000"
Example
The following example retrieves the thumbprint of the first certificate found in the CurrentUser Personal certificate store.
using System;
using System.Security.Cryptography.X509Certificates;
public class Example
{
public static void Main()
{
try
{
// Get the current user's personal certificate store
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
// Check if there are any certificates in the store
if (store.Certificates.Count > 0)
{
// Get the first certificate
X509Certificate2 certificate = store.Certificates[0];
// Get the thumbprint
string thumbprint = certificate.Thumbprint;
Console.WriteLine($"Certificate Thumbprint: {thumbprint}");
}
else
{
Console.WriteLine("No certificates found in the CurrentUser Personal store.");
}
store.Close();
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
Requirements
.NET Framework**
Supported in: 4.5, 4.0, 3.5, 3.0, 2.0
.NET Standard**
Supported in: 2.1, 2.0
.NET Core**
Supported in: 3.0, 2.1, 2.0