PDA

View Full Version : HMAC SHA1 algorithm



Jeremy__
03-03-2021, 01:32 AM
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

Miranda34
06-26-2023, 08:19 PM
The United States Government published the SHA-1 (Secure Hash Algorithm, commonly known as SHS, Secure Hash Standard) cryptographic hash algorithm.

arnelgp
06-27-2023, 05:27 PM
Hexadecimal, Octal, Binary are but representation of data in another Number (computer system).

namdosan1409
07-18-2023, 11:40 PM
HMAC algorithm stands for Hashed or Hash-based Message Authentication Code.

car games (https://cargames.one)

Aussiebear
07-19-2023, 05:16 AM
This thread is now closed given that recent posts have not been constructive to the intent of the thread.