Bonjour,
Pour un projet entreprise, je dois, via un fichier Excel, hacher des données du type Text String avec une clé secrète Hex String via l'algorithme HMAC SHA1, auriez vous des idées pour le faire ?
J'ai trouvé le code ci-dessous qui fonctionne bien mais la clé secrète n'est pas en hexadécimal..
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
Merci d'avance,
Jérémy