RSACryptoServiceProvider.VerifyHash 方法

定义

验证数字签名有效。

重载

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

通过使用提供的公钥计算签名中的哈希值,然后将其与提供的哈希值进行比较来验证数字签名是否有效。

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

通过使用指定的哈希算法和填充确定签名中的哈希值,并将其与提供的哈希值进行比较,以此验证数字签名是否有效。

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

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
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)

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
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

适用于