Επεξεργασία

Κοινή χρήση μέσω


RSACryptoServiceProvider.VerifyHash Method

Definition

Verifies that a digital signature is valid.

Overloads

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

Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the provided hash value.

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

Verifies that a digital signature is valid by determining the hash value in the signature using the specified hashing algorithm and padding, and comparing it to the provided hash value.

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

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs

Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the provided hash value.

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

Parameters

rgbHash
Byte[]

The hash value of the signed data.

str
String

The hash algorithm identifier (OID) used to create the hash value of the data.

rgbSignature
Byte[]

The signature data to be verified.

Returns

true if the signature is valid; otherwise, false.

Exceptions

The rgbHash parameter is null.

-or-

The rgbSignature parameter is null.

The cryptographic service provider (CSP) cannot be acquired.

-or-

The signature cannot be verified.

Examples

The following example shows how to use the VerifyHash method to verify a signature. This code example is part of a larger example provided for the SignHash method.

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

Remarks

This method verifies the RSA digital signature produced by the SignHash method. The signature is verified by obtaining the hash value from the signature using the public key it was signed with, and comparing that value to the hash value of the provided data.

The valid hash algorithms are SHA1 and MD5. The algorithm identifier can be derived from the hash name by using the MapNameToOID method.

Due to collision problems with SHA1 and MD5, Microsoft recommends a security model based on SHA256 or better.

See also

Applies to

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

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs

Verifies that a digital signature is valid by determining the hash value in the signature using the specified hashing algorithm and padding, and comparing it to the provided hash value.

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

Parameters

hash
Byte[]

The hash value of the signed data.

signature
Byte[]

The signature data to be verified.

hashAlgorithm
HashAlgorithmName

The hash algorithm name used to create the hash value.

padding
RSASignaturePadding

The padding.

Returns

true if the signature is valid; otherwise, false.

Exceptions

hashAlgorithm is null or Empty.

hash is null.

-or-

padding is null.

padding does not equal Pkcs1.

Applies to