Consulting

Results 1 to 5 of 5

Thread: HMAC SHA1 algorithm

  1. #1
    VBAX Newbie
    Joined
    Mar 2021
    Posts
    1
    Location

    HMAC SHA1 algorithm

    I must, with Excel file, hash a data list (Text String) with secret key (Hex String) with HMAC SHA1 algorithm, do you have some ideas ?
    I found this code (see below) but the secret key is not in hexadecimal...

    Public Function HEX_HMACSHA1(ByVal sTextToHash As String, ByVal sSharedSecretKey As Variant)
        Dim asc As Object, enc As Object
        Dim TextToHash() As Byte
        Dim SharedSecretKey() As Byte
        
        Set asc = CreateObject("System.Text.UTF8Encoding")
        Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
     
        TextToHash = asc.Getbytes_4(sTextToHash)
        SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
        enc.Key = SharedSecretKey
    
    
        Dim Bytes() As Byte
        Bytes = enc.ComputeHash_2((TextToHash))
        'HEX_HMACSHA1 = ConvToHexString(Bytes)
        Set asc = Nothing
        Set enc = Nothing
     
    End Function
     
    
    
    Private Function ConvToHexString(vIn As Variant) As Variant
        'Check that Net Framework 3.5 (includes .Net 2 and .Net 3 is installed in windows
        'and not just Net Advanced Services
        
        Dim oD As Object
          
        Set oD = CreateObject("MSXML2.DOMDocument")
          
          With oD
            .LoadXML "<root />"
            .DocumentElement.DataType = "bin.Hex"
            .DocumentElement.nodeTypedValue = vIn
          End With
        ConvToHexString = Replace(oD.DocumentElement.Text, vbLf, "")
        
        Set oD = Nothing
    
    
    End Function



    Jérémy

  2. #2
    The United States Government published the SHA-1 (Secure Hash Algorithm, commonly known as SHS, Secure Hash Standard) cryptographic hash algorithm.
    Last edited by Aussiebear; 06-26-2023 at 08:28 PM. Reason: Removed spam link in post

  3. #3
    Hexadecimal, Octal, Binary are but representation of data in another Number (computer system).

  4. #4
    HMAC algorithm stands for Hashed or Hash-based Message Authentication Code.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,053
    Location
    This thread is now closed given that recent posts have not been constructive to the intent of the thread.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •