संपादित करें

इसके माध्यम से साझा किया गया


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.

public:
 virtual cli::array <System::Byte> ^ GetCertHash();
public virtual byte[] GetCertHash ();
abstract member GetCertHash : unit -> byte[]
override this.GetCertHash : unit -> byte[]
Public Overridable Function GetCertHash () As Byte()

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.

using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int 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.
   array<Byte>^results = cert->GetCertHash();
}

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();
    }
}
Imports System.Security.Cryptography.X509Certificates




Public Class X509
   
   
   Public Shared Sub Main()
      
      ' The path to the certificate.
      Dim Certificate As String = "Certificate.cer"
      
      ' Load the certificate into an X509Certificate object.
      Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(Certificate)
      
      ' Get the value.
      Dim results As Byte() = cert.GetCertHash()
   End Sub 
End Class

Applies to

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.

public:
 virtual cli::array <System::Byte> ^ GetCertHash(System::Security::Cryptography::HashAlgorithmName hashAlgorithm);
public virtual byte[] GetCertHash (System.Security.Cryptography.HashAlgorithmName hashAlgorithm);
abstract member GetCertHash : System.Security.Cryptography.HashAlgorithmName -> byte[]
override this.GetCertHash : System.Security.Cryptography.HashAlgorithmName -> byte[]
Public Overridable Function GetCertHash (hashAlgorithm As HashAlgorithmName) As Byte()

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