X509Certificate.GetCertHash 方法

定义

返回 X509Certificate 对象的哈希值。

重载

GetCertHash()

将 X.509v3 证书的哈希值作为字节数组返回。

GetCertHash(HashAlgorithmName)

返回使用指定加密哈希算法计算的 X.509v3 证书的哈希值。

GetCertHash()

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

将 X.509v3 证书的哈希值作为字节数组返回。

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 证书的哈希值。

示例

以下示例使用 GetCertHash 方法使用 X.509 证书的哈希值填充字节数组。

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)

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

返回使用指定加密哈希算法计算的 X.509v3 证书的哈希值。

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

要使用的加密哈希算法的名称。

返回

Byte[]

包含 X.509 证书哈希值的字节数组。

例外

hashAlgorithm.Namenull 或空字符串。

hashAlgorithm 不是已知的哈希算法。

另请参阅

适用于