THE FORUM IS IN READ-ONLY MODE

This forum is in read-only mode. The new forum is live at https://discourse.openbullet.dev and registrations are open!

How to convert a String into HMAC-SHA1



  • Hello
    I have found this function to convert a string to HMAC-SHA1. This function is working fine but I want the output in Base64 like in OB. Anybody know how I can get the desired result. Here is the function

    Public Shared Function HMACSHA1(ByVal StringToHash As String, ByVal HachKey As String) As String
            Dim myEncoder As New System.Text.UTF8Encoding
            Dim Key() As Byte = myEncoder.GetBytes(HachKey)
            Dim Text() As Byte = myEncoder.GetBytes(StringToHash)
            Dim myHMACSHA1 As New System.Security.Cryptography.HMACSHA1(Key)
            Dim HashCode As Byte() = myHMACSHA1.ComputeHash(Text)
            Dim hash As String = Replace(BitConverter.ToString(HashCode), "-", "")
            Return hash.ToUpper
        End Function
    


  • @King_Kong You can combine with this base64encode.vb


  • Admin

    Remove these lines

    Dim hash As String = Replace(BitConverter.ToString(HashCode), "-", "")
    Return hash.ToUpper
    

    and instead use this (I write in C# cause I don't know VB.NET)

    return Convert.ToBase64String(HashCode);
    


  • @Ruri Thanks it works like a charm


Log in to reply