Link to home
Start Free TrialLog in
Avatar of rp
rpFlag for Portugal

asked on

vb.net how to verify signature made by signdata

Dim sign As Byte() = privatekey.SignData(data, "SHA1")

ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rp

ASKER

In this function:
- datatoverify - is data before signed ?
- signeddata - is data after signed
- key - is the public or private key

Function VerifySignedHash(ByVal DataToVerify() As Byte, ByVal SignedData() As Byte, ByVal Key As RSAParameters) As Boolean
        Try
            ' Create a new instance of RSACryptoServiceProvider using the
            ' key from RSAParameters.
            Dim RSAalg As New RSACryptoServiceProvider

            RSAalg.ImportParameters(Key)

            ' Verify the data using the signature.  Pass a new instance of SHA1CryptoServiceProvider
            ' to specify the use of SHA1 for hashing.
            Return RSAalg.VerifyData(DataToVerify, New SHA1CryptoServiceProvider, SignedData)

        Catch e As CryptographicException
            Console.WriteLine(e.Message)

            Return False
        End Try
    End Function