This documentation is archived and is not being maintained.

RSACryptoServiceProvider.VerifyData Method

Updated: December 2010

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 hash value of the provided data.

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

public bool VerifyData(
	byte[] buffer,
	Object halg,
	byte[] signature
)

Parameters

buffer
Type: System.Byte[]

The data that was signed.

halg
Type: System.Object

The name of the hash algorithm used to create the hash value of the data.

signature
Type: System.Byte[]

The signature data to use for verification.

Return Value

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

ExceptionCondition
ArgumentNullException

The halg parameter is null.

ArgumentException

The halg parameter is not a valid type.

This method verifies the RSA digital signature produced by the SignData 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 halg parameter can accept a String, a HashAlgorithm, or a Type.

The following example shows how to use the VerifyData(Byte[], Object, 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;

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0

Date

History

Reason

December 2010

Updated the summary and the example.

Customer feedback.

Show: