Home All Groups Group Topic Archive Search About

How can I set the HMACSHA1 key to hex?

Author
17 May 2006 1:41 AM
RedEye
I have tested the output against a hash calculation application. Every thing
works fine but the only problem is that in order for the hash to match the
ap's hash the HMACSHA1.Key needs to be set to HEX. Is there a different
encoding type I should be using?

Any help would be appreciated.

Below is the code in it's current form.

Public Function CalculateHMAC(ByVal data As String, ByVal key As String) As
String
Dim bData As Byte() = Encoding.UTF8.GetBytes(data)
Dim bKey As Byte() = Encoding.UTF8.GetBytes(key)
Dim hmac As HMACSHA1 = New HMACSHA1(bKey)

Using cryptoStream As CryptoStream = New CryptoStream(Stream.Null, hmac,
CryptoStreamMode.Write)
  cryptoStream.Write(bData, 0, bData.Length)
End Using

Return HexEncoding.ToString(hmac.Hash)
End Function


Thanks!!

Author
17 May 2006 1:55 AM
RedEye
I got it to work...

It always seem to work out after you post it to the group.

Thanks!


Show quote
"RedEye" <redeye***@hotmail.com> wrote in message
news:OgYtFMVeGHA.764@TK2MSFTNGP05.phx.gbl...
>I have tested the output against a hash calculation application. Every
>thing works fine but the only problem is that in order for the hash to
>match the ap's hash the HMACSHA1.Key needs to be set to HEX. Is there a
>different encoding type I should be using?
>
> Any help would be appreciated.
>
> Below is the code in it's current form.
>
> Public Function CalculateHMAC(ByVal data As String, ByVal key As String)
> As String
> Dim bData As Byte() = Encoding.UTF8.GetBytes(data)
> Dim bKey As Byte() = Encoding.UTF8.GetBytes(key)
> Dim hmac As HMACSHA1 = New HMACSHA1(bKey)
>
> Using cryptoStream As CryptoStream = New CryptoStream(Stream.Null, hmac,
> CryptoStreamMode.Write)
>  cryptoStream.Write(bData, 0, bData.Length)
> End Using
>
> Return HexEncoding.ToString(hmac.Hash)
> End Function
>
>
> Thanks!!
>
>

AddThis Social Bookmark Button