RSACryptoServiceProvider.VerifyData(Byte[], Object, Byte[]) 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 hash value of the provided data.

 bool VerifyData(cli::array <System::Byte> ^ buffer, System::Object ^ halg, cli::array <System::Byte> ^ signature);
public bool VerifyData (byte[] buffer, object halg, byte[] signature);
member this.VerifyData : byte[] * obj * byte[] -> bool
Public Function VerifyData (buffer As Byte(), halg As Object, signature As Byte()) As Boolean



The data that was signed.


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


The signature data to be verified.


true if the signature is valid; otherwise, false.


The halg parameter is null.

The halg parameter is not a valid 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;
   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;

    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

    dataOK = rsaCSP.VerifyData(signedData, CryptoConfig.MapNameToOID("SHA1"), signature)
    hashedData = hash.ComputeHash(signedData)
    Return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"), signature)
End Function 'VerifyHash


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.

Applies to

See also