X509Certificate.GetCertHash Method

Definition

Returns the hash value for an X509Certificate object.

Overloads

GetCertHash()

Returns the hash value for the X.509v3 certificate as an array of bytes.

GetCertHash(HashAlgorithmName)

Returns the hash value for the X.509v3 certificate that is computed by using the specified cryptographic hash algorithm.

GetCertHash()

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

Returns the hash value for the X.509v3 certificate as an array of bytes.

C#
public virtual byte[] GetCertHash();

Returns

Byte[]

The hash value for the X.509 certificate.

Examples

The following example uses the GetCertHash method to fill an array of bytes with the hash value for an X.509 certificate.

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.
        byte[] results = cert.GetCertHash();
    }
}

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, 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 1.3, 1.4, 1.6, 2.0, 2.1

GetCertHash(HashAlgorithmName)

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

Returns the hash value for the X.509v3 certificate that is computed by using the specified cryptographic hash algorithm.

C#
public virtual byte[] GetCertHash(System.Security.Cryptography.HashAlgorithmName hashAlgorithm);

Parameters

hashAlgorithm
HashAlgorithmName

The name of the cryptographic hash algorithm to use.

Returns

Byte[]

A byte array that contains the hash value for the X.509 certificate.

Exceptions

hashAlgorithm.Name is null or an empty string.

hashAlgorithm is not a known hash algorithm.

See also

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