How can I set the HMACSHA1 key to hex?

Discussion in 'ASP .Net Security' started by RedEye, May 17, 2006.

  1. RedEye

    RedEye Guest

    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!!
     
    RedEye, May 17, 2006
    #1
    1. Advertising

  2. RedEye

    RedEye Guest

    I got it to work...

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

    Thanks!


    "RedEye" <> wrote in message
    news:...
    >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!!
    >
    >
     
    RedEye, May 17, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timo Nentwig

    JCE: generateing HmacSHA1

    Timo Nentwig, Dec 3, 2004, in forum: Java
    Replies:
    2
    Views:
    738
    Timo Nentwig
    Dec 5, 2004
  2. Replies:
    10
    Views:
    6,273
    Neredbojias
    Aug 19, 2005
  3. Bengt Richter
    Replies:
    6
    Views:
    488
    Juha Autero
    Aug 19, 2003
  4. jack
    Replies:
    4
    Views:
    596
  5. M P
    Replies:
    1
    Views:
    500
Loading...

Share This Page