HMAC-SHA1 signature + hash

Hi folks,

because of an API service I need to use, I have to hash a string. Thought it was a simple task, but now I am only getting confused.
From an userID (say “12345”) I need to calculate the [quote]uid_signature that is the HMAC-SHA1 signature of the userID. The string is hex-encoded. The key is your user token[/quote]…etc. (quoted from service documentation)

I did some test, but got runtime errors like “Encountered invalid character.”
Maybe it is a noob question, but have mercy, it’s Monday…

What’s the code from your test that resulted in “Encountered invalid character.” ?

[code]Dim encryptedValue As String

encryptedValue = Crypto.Hash(“DataToEncrypt”, Crypto.Algorithm.SHA1)

outsha1.Text=encryptedValue[/code]

but this is only the last of n quick tests I did, following the documentation or some example. I really didn’t go into deep testing.

Are you really encrypting the string “DataToEncrypt”?
That’s likely where the problem is.

You might also need to EncodeHex the returned MemoryBlock before trying to display it in a TextArea. I only looked a a String variable in the debugger when testing.

I’m betting it’s that you have to encodeHex on the result, as Tim suggested.

[code]Dim encryptedValue As String
encryptedValue = Crypto.Hash(“DataToEncrypt”, Crypto.Algorithm.SHA1)

outsha1.Text=EncodeHex(encryptedValue)[/code]

Works. Thank you, so easy I still wonder what I tried for 1 hour today… :slight_smile: