CertificateThumbprint Class
Microsoft.IdentityModel.Tokens
Represents a certificate thumbprint for a certificate.
This class provides a way to represent and manage the thumbprint of an X.509 certificate. A thumbprint is a unique identifier for a certificate and is often used for matching and authentication purposes.
Table of Contents
Properties
Value Property
Gets the string representation of the certificate thumbprint.
public string Value { get; }
Constructors
CertificateThumbprint(string) Constructor
Initializes a new instance of the CertificateThumbprint class with the specified thumbprint string.
public CertificateThumbprint(string thumbprint)
Parameters
| Name |
Description |
thumbprint |
The thumbprint string to initialize the object with. Must be a valid hex string representation of a thumbprint. |
CertificateThumbprint(byte[]) Constructor
Initializes a new instance of the CertificateThumbprint class with the specified thumbprint byte array.
public CertificateThumbprint(byte[] thumbprint)
Parameters
| Name |
Description |
thumbprint |
The thumbprint byte array to initialize the object with. |
Methods
Equals Method
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
GetHashCode Method
Serves as the default hash function.
public override int GetHashCode()
ToString Method
Returns the string representation of the certificate thumbprint.
public override string ToString()
Operators
== Operator
Compares two CertificateThumbprint objects for equality.
public static bool operator ==(CertificateThumbprint left, CertificateThumbprint right)
!= Operator
Compares two CertificateThumbprint objects for inequality.
public static bool operator !=(CertificateThumbprint left, CertificateThumbprint right)
Example Usage
using System;
using Microsoft.IdentityModel.Tokens;
public class Example
{
public static void Main(string[] args)
{
// Initialize with a string
string thumbprintString = "a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4";
CertificateThumbprint thumbprint1 = new CertificateThumbprint(thumbprintString);
Console.WriteLine($"Thumbprint 1 (string): {thumbprint1.Value}");
// Initialize with a byte array
byte[] thumbprintBytes = {
0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6, 0x78, 0x90,
0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6, 0x78, 0x90,
0xa1, 0xb2, 0xc3, 0xd4
};
CertificateThumbprint thumbprint2 = new CertificateThumbprint(thumbprintBytes);
Console.WriteLine($"Thumbprint 2 (bytes): {thumbprint2.Value}");
// Compare thumbprints
if (thumbprint1 == thumbprint2)
{
Console.WriteLine("Thumbprints are equal.");
}
else
{
Console.WriteLine("Thumbprints are not equal.");
}
}
}