RSACryptoServiceProvider.VerifyHash 方法

定義

驗證數位簽章是否有效。

多載

VerifyHash(Byte[], String, Byte[])

使用提供的公開金鑰,並和提供的雜湊值比較,來為簽章判斷雜湊值,藉此驗證數位簽章是否有效。

VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding)

使用指定的雜湊演算法和填補,並和提供的雜湊值比較,來為簽章判斷雜湊值,藉此驗證數位簽章是否有效。

VerifyHash(Byte[], String, Byte[])

來源:
RSACryptoServiceProvider.Unix.cs
來源:
RSACryptoServiceProvider.Unix.cs
來源:
RSACryptoServiceProvider.Unix.cs

使用提供的公開金鑰,並和提供的雜湊值比較,來為簽章判斷雜湊值,藉此驗證數位簽章是否有效。

public:
 bool VerifyHash(cli::array <System::Byte> ^ rgbHash, System::String ^ str, cli::array <System::Byte> ^ rgbSignature);
public bool VerifyHash (byte[] rgbHash, string str, byte[] rgbSignature);
override this.VerifyHash : byte[] * string * byte[] -> bool
member this.VerifyHash : byte[] * string * byte[] -> bool
Public Function VerifyHash (rgbHash As Byte(), str As String, rgbSignature As Byte()) As Boolean

參數

rgbHash
Byte[]

已簽署資料的雜湊值。

str
String

用以建立該資料雜湊值的雜湊演算法識別項 (OID)。

rgbSignature
Byte[]

要驗證的簽章資料。

傳回

如果簽章有效則為 true,否則為 false

例外狀況

rgbHash 參數為 null

-或-

rgbSignature 參數為 null

無法取得密碼編譯服務提供者 (CSP)。

-或-

無法驗證簽章。

範例

下列範例示範如何使用 VerifyHash 方法來驗證簽章。 此程式碼範例是方法所提供較大範例的 SignHash 一部分。

bool VerifyHash( RSAParameters rsaParams, array<Byte>^signedData, array<Byte>^signature )
{
   RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
   SHA1Managed^ hash = gcnew SHA1Managed;
   array<Byte>^hashedData;
   rsaCSP->ImportParameters( rsaParams );
   bool dataOK = rsaCSP->VerifyData(signedData, CryptoConfig::MapNameToOID("SHA1"), signature);
   hashedData = hash->ComputeHash( signedData );
   return rsaCSP->VerifyHash( hashedData, CryptoConfig::MapNameToOID( "SHA1" ), signature );
}
public bool VerifyHash(RSAParameters rsaParams, byte[] signedData, byte[] signature)
{
    RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
    SHA1Managed hash = new SHA1Managed();
    byte[] hashedData;

    rsaCSP.ImportParameters(rsaParams);
    bool dataOK = rsaCSP.VerifyData(signedData, CryptoConfig.MapNameToOID("SHA1"), signature);
    hashedData = hash.ComputeHash(signedData);
    return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"), signature);
}
Public Function VerifyHash(ByVal rsaParams As RSAParameters, ByVal signedData() As Byte, ByVal signature() As Byte) As Boolean
    Dim rsaCSP As New RSACryptoServiceProvider()
    Dim hash As New SHA1Managed()
    Dim hashedData() As Byte
    Dim dataOK As Boolean

    rsaCSP.ImportParameters(rsaParams)
    dataOK = rsaCSP.VerifyData(signedData, CryptoConfig.MapNameToOID("SHA1"), signature)
    hashedData = hash.ComputeHash(signedData)
    Return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"), signature)
End Function 'VerifyHash

備註

這個方法會 RSA 驗證 方法所產生的 SignHash 數位簽章。 簽章的驗證方式是使用簽章簽署的公開金鑰,從簽章取得雜湊值,並將該值與所提供資料的雜湊值進行比較。

有效的雜湊演算法為 SHA1MD5 。 演算法識別碼可以使用 方法來衍生自雜湊名稱 MapNameToOID

由於 SHA1 和 MD5 發生衝突問題,Microsoft 建議根據 SHA256 或更好的安全性模型。

另請參閱

適用於

VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding)

來源:
RSACryptoServiceProvider.Unix.cs
來源:
RSACryptoServiceProvider.Unix.cs
來源:
RSACryptoServiceProvider.Unix.cs

使用指定的雜湊演算法和填補,並和提供的雜湊值比較,來為簽章判斷雜湊值,藉此驗證數位簽章是否有效。

public:
 override bool VerifyHash(cli::array <System::Byte> ^ hash, cli::array <System::Byte> ^ signature, System::Security::Cryptography::HashAlgorithmName hashAlgorithm, System::Security::Cryptography::RSASignaturePadding ^ padding);
public override bool VerifyHash (byte[] hash, byte[] signature, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.Security.Cryptography.RSASignaturePadding padding);
override this.VerifyHash : byte[] * byte[] * System.Security.Cryptography.HashAlgorithmName * System.Security.Cryptography.RSASignaturePadding -> bool
Public Overrides Function VerifyHash (hash As Byte(), signature As Byte(), hashAlgorithm As HashAlgorithmName, padding As RSASignaturePadding) As Boolean

參數

hash
Byte[]

已簽署資料的雜湊值。

signature
Byte[]

要驗證的簽章資料。

hashAlgorithm
HashAlgorithmName

用來建立該雜湊值的雜湊演算法名稱。

padding
RSASignaturePadding

填補。

傳回

如果簽章有效則為 true,否則為 false

例外狀況

hashAlgorithmnullEmpty

hashnull

-或-

paddingnull

padding 不等於 Pkcs1

適用於