Hi again,
I tried to write the following functions:
Public Function GetSignedHash(ByVal str As String) As Byte()
Dim ha As HashAlgorithm = SHA1.Create()
ha.ComputeHash(Encoding.ASCII.GetBytes(str))
GetSignedHash = rsa.SignHash(ha.Hash, CryptoConfig.MapNameToOID("SHA1"))
End Function
Public Function VerifySignedHash(ByVal bytes() As Byte) As Boolean
Dim ha As HashAlgorithm = SHA1.Create()
Dim rsapartner As New RSACryptoServiceProvider
rsapartner.FromXmlString(partnerpk)
ha.ComputeHash(bytes)
VerifySignedHash = rsapartner.VerifyHash(ha.Hash, CryptoConfig.MapNameToOID("SHA1"), bytes)
End Function
The first function hashes and signes some data, using the private key (in rsa), the other function uses the public key, that is stored in an XML string, to verify the hash. Now, here's the test code:
Dim serverhash() As Byte
serverhash = server.GetSignedHash("This is a test")
MsgBox(client.VerifySignedHash(serverhash))
This MsgBox should always print "true", but it doesn't..., so VerifyHash is always false. Can anyone tell me why?
Thanks a lot
Gordon