Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

RSACryptoServiceProvider.VerifyHash Method

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.

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)
public bool VerifyHash(
	byte[] rgbHash,
	string str,
	byte[] rgbSignature


Type: System.Byte[]
The hash value of the signed data.
Type: System.String
The hash algorithm identifier (OID) used to create the hash value of the data.
Type: System.Byte[]
The signature data to be verified.

Return Value

Type: System.Boolean
true if the signature is valid; otherwise, false.

The rgbHash parameter is null.


The rgbSignature parameter is null.


The cryptographic service provider (CSP) cannot be acquired.


The signature cannot be verified.

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.

The following example shows how to use the VerifyHash(Byte[], String, Byte[]) method to verify a signature. This code example is part of a larger example provided for the SignHash(Byte[], String) method.

public bool VerifyHash(RSAParameters rsaParams, byte[] signedData, byte[] signature)
    RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
    SHA1Managed hash = new SHA1Managed();
    byte[] hashedData;

    bool dataOK = rsaCSP.VerifyData(signedData, CryptoConfig.MapNameToOID("SHA1"), signature);
    hashedData = hash.ComputeHash(signedData);
    return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"), signature);

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.