RSACryptoServiceProvider::VerifyHash Method (array<Byte>^, String^, 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 provided hash value.
Assembly: mscorlib (in mscorlib.dll)
public: bool VerifyHash( array<unsigned char>^ rgbHash, String^ str, array<unsigned char>^ rgbSignature )
Parameters
- rgbHash
-
Type:
array<System::Byte>^
The hash value of the signed data.
- str
-
Type:
System::String^
The hash algorithm identifier (OID) used to create the hash value of the data.
- rgbSignature
-
Type:
array<System::Byte>^
The signature data to be verified.
| Exception | Condition |
|---|---|
| ArgumentNullException | The rgbHash parameter is null. -or- The rgbSignature parameter is null. |
| CryptographicException | The cryptographic service provider (CSP) cannot be acquired. -or- 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 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 ); }
Available since 1.1
Windows Phone Silverlight
Available since 7.1