Hachage HMAC SHA1

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

Bonjour,

ou que celui-ci https://forum.excel-pratique.com/excel/variable-hexadecimale-sous-vba-algorithme-chiffrement-153891
resté sans réponse de ta part...

Si tu as eu la solution sur un des nombreux autres forums où tu as posté, ça serait bien de la partager
eric

Bonjour eriiiic

ah oui quand même, un sujet par jour ...

@Jeremy : peux-tu nous faire un retour ?

Rechercher des sujets similaires à "hachage hmac sha1"