Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RSACryptoServiceProvider::VerifyData Method (array<Byte>^, Object^, array<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 hash value of the provided data.

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

public:
bool VerifyData(
	array<unsigned char>^ buffer,
	Object^ halg,
	array<unsigned char>^ signature
)

Parameters

buffer
Type: array<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: array<System::Byte>^

The signature data to be verified.

Return Value

Type: System::Boolean

true if the signature is valid; otherwise, false.

Exception Condition
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 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 );
}

.NET Framework
Available since 1.1
Windows Phone Silverlight
Available since 7.1
Return to top
Show:
© 2017 Microsoft