0

I'm trying to produce a "Signature" SHA1 string to append to a URI.

I've got a string URI piece and a secret from the target vendor. I need to take the URI text and the secret and produce a signature string that looks similar to this in formatting: "4623B7B8-18A6-4B2C-B2C1-18157F5C4AFE"

Imports System.Security.Cryptography

'This is the String to use to create the SHA1
Dim DataToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text)
'This is the secret key given to me from the vendor
Dim SecretKey() As Byte = System.Text.Encoding.ASCII.GetBytes(TextBox2.Text)
    Using myhmac As New HMACSHA1(SecretKey)
         Using MS As New IO.MemoryStream(DataToHash)
              Dim HashValue As Byte() = myhmac.ComputeHash(MS)
              'This is the output or signature
              TextBox3.Text = System.Text.Encoding.Unicode.GetString(HashValue)
         End Using
    End Using

I've got this code from someone but the output testbox3.text looks like Chinese.

enter image description here

What am I missing?

Cù Đức Hiếu
  • 5,569
  • 4
  • 27
  • 35
LightStamp
  • 39
  • 7
  • 1
    Put your cursor on `HMACSHA1`. Press F1. Drill into the `HashAlgorithm.ComputeHash Method (Byte())` method. Use the code in the *excellent* example there to convert the returned bytes to text. BTW, streams have nothing to do with it. – Ňɏssa Pøngjǣrdenlarp Oct 31 '16 at 21:04
  • The kicker was this line: TheStoreResponse = Await aResponse.Content.ReadAsStringAsync() – LightStamp Nov 14 '16 at 15:05

0 Answers0