0

I have a secret key : zbPsRqhNg It needs to be encoded in vb.net

I am using the following source :

Friend Overrides Function PostToLender(sData As String) As String
            '' sData contains the XML to post
            '' lendertier.ServiceURL is the URL to post to
            '' so build a checksum from the XML data
            Dim Secret As String = lendertier.Credential1  '' store the secret key in the tier's 1st credential
            Dim hash As HMACSHA1 = New HMACSHA1()
            hash.Key = UTF8.GetBytes(Secret)
            Dim checksum As String = UTF8.GetString(hash.ComputeHash(UTF8.GetBytes(sData)))

            '' append checksum to URL
            lendertier.ServiceURL &= "&checksum=" & checksum

            '' Complete normal processing
            Return MyBase.PostToLender(sData)
        End Function

This is not working and the result which is not correct

checksum=%EF%BF%BD%EF%BF%BD&%EF%BF%BDg%EF%BF%BD*(%

it should be

6d91394d2b57ed448f45efcd2aeb773238b9055d

so i tryed which i think i did this wrong:

Dim Secret As String = lendertier.Credential3  '' store the secret key in the tier's 1st credential
Dim hash As New SHA1CryptoServiceProvider()
            HashCore = UTF8.GetBytes(Secret)
Dim checksum As String = UTF8.GetString(hash.ComputeHash(UTF8.GetBytes(sData)))

'' append checksum to URL
            lendertier.ServiceURL &= "?checksum=" & checksum

Neither work , if i could could get a little assistance that would be great.

MatHatrik
  • 762
  • 1
  • 6
  • 16
  • You probably want to url-encode the Base64 encoding of the hash to pass it in a URL: [Passing base64 encoded strings in URL](http://stackoverflow.com/a/1374794/1115360). – Andrew Morton Mar 05 '15 at 09:17

1 Answers1

0

Think this is what you are looking for

Dim checksum As String = Convert.ToBase64String(hash.ComputeHash(UTF8.GetBytes(sData)))
David Sdot
  • 2,343
  • 1
  • 20
  • 26
  • Hi David, can you give me a complete solution as i am getting an error on the following HashCore = UTF8.GetBytes(Secret) . – MatHatrik Mar 05 '15 at 12:19