X509Certificate.GetCertHash 方法

定義

傳回 X509Certificate 物件的雜湊值。Returns the hash value for an X509Certificate object.

多載

GetCertHash()

將 X.509v3 憑證的雜湊值 (Hash Value) 傳回為位元組陣列。Returns the hash value for the X.509v3 certificate as an array of bytes.

GetCertHash(HashAlgorithmName)

傳回使用指定密碼編譯雜湊演算法所計算 X.509v3 憑證的雜湊值。Returns the hash value for the X.509v3 certificate that is computed by using the specified cryptographic hash algorithm.

GetCertHash()

將 X.509v3 憑證的雜湊值 (Hash Value) 傳回為位元組陣列。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()

傳回

Byte[]

X.509 憑證的雜湊值。The hash value for the X.509 certificate.

範例

下列範例會使用 GetCertHash 方法,以 x.509 憑證的雜湊值來填入位元組陣列。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 

GetCertHash(HashAlgorithmName)

傳回使用指定密碼編譯雜湊演算法所計算 X.509v3 憑證的雜湊值。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()

參數

hashAlgorithm
HashAlgorithmName

要使用的密碼編譯雜湊演算法名稱。The name of the cryptographic hash algorithm to use.

傳回

Byte[]

位元組陣列,其中包含 X.509 憑證的雜湊值。A byte array that contains the hash value for the X.509 certificate.

例外狀況

hashAlgorithm.NamehashAlgorithm.Name null 或空字串。is null or an empty string.

hashAlgorithm 不是已知的雜湊演算法。hashAlgorithm is not a known hash algorithm.

另請參閱

適用於