X509Certificate.GetCertHashString Method

Definition

Returns a hexadecimal string that contains the hash value for the X.509v3 certificate.

Overloads

GetCertHashString()

Returns the SHA1 hash value for the X.509v3 certificate as a hexadecimal string.

GetCertHashString(HashAlgorithmName)

Returns a hexadecimal string containing the hash value for the X.509v3 certificate computed using the specified cryptographic hash algorithm.

GetCertHashString()

Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs

Returns the SHA1 hash value for the X.509v3 certificate as a hexadecimal string.

C#
public virtual string GetCertHashString ();

Returns

The hexadecimal string representation of the X.509 certificate hash value.

Examples

The following example uses the GetCertHashString method to get an X.509 certificate hash value, convert it to a string, and display it to the console.

C#

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

public class X509
{

    public static void Main()
    {

        // The path to the certificate.
        string Certificate =  "Certificate.cer";

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

        // Get the value.
        string results = cert.GetCertHashString();

        // Display the value to the console.
        Console.WriteLine(results);
    }
}

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetCertHashString(HashAlgorithmName)

Source:
X509Certificate.cs
Source:
X509Certificate.cs
Source:
X509Certificate.cs

Returns a hexadecimal string containing the hash value for the X.509v3 certificate computed using the specified cryptographic hash algorithm.

C#
public virtual string GetCertHashString (System.Security.Cryptography.HashAlgorithmName hashAlgorithm);

Parameters

hashAlgorithm
HashAlgorithmName

The name of the cryptographic hash algorithm to use.

Returns

The hexadecimal string representation of the X.509 certificate hash value.

Exceptions

hashAlgorithm.Name is null or an empty string.

hashAlgorithm is not a known hash algorithm.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.8, 4.8.1
.NET Standard 2.1