i got a code to convert a string to a hmac sha1 encyption. However, i cant get it to work. Here is my code:
Public Shared Function HashString(ByVal StringToHash As String) As String
Dim myEncoder As New System.Text.UTF32Encoding
Dim Key() As Byte = myEncoder.GetBytes("thisismykey")
Dim Text() As Byte = myEncoder.GetBytes(StringToHash)
Dim myHMACSHA1 As New System.Security.Cryptography.HMACSHA1(Key)
Dim HashCode As Byte() = myHMACSHA1.ComputeHash(Text)
Return Convert.ToBase64String(HashCode)
End Function
When i run the function like this:
TextBox1.Text = HashString("thisismystring")
I get 04p075DKS2Suw9jGQKC5Q7mYjvI=
in the textbox.
What i should get is c2bc9dd26b76d5b61a40ac788220eef0b26cb2bb
Anyone has any idea on how to solve this? Please help :)
correction depuis maj EXCEL,
pour faire du mD5, il faut copier coller le code ci-dessous
Your
04p075DKS2Suw9jGQKC5Q7mYjvI=
is in Base64. Yourc2bc9dd26b76d5b61a40ac788220eef0b26cb2bb
is in hex. You need to convert one into the other format so you can compare them correctly.ETA: I checked, the two don't match, your hex gives me
wryd0mt21bYaQKx4giDu8LJssrs=
in Base64. I suspect the problem may lie with using UTF32 encoding, this is very unusual. UTF8 or UTF16 are much more common. Try UTF8 first.I found the solution. I just converted the byte to a string, made it to lower and replaced - with nothing. See my code below :)
Example Usage:
Thanks for your help :)