Skip to content

Instantly share code, notes, and snippets.

@vector-sec
Created August 4, 2016 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vector-sec/f814903b633121d9948ad643f583556f to your computer and use it in GitHub Desktop.
Save vector-sec/f814903b633121d9948ad643f583556f to your computer and use it in GitHub Desktop.
VBScript implementation of SHA1HMAC meeting Duo Security's specifications
Function ToString(rabyt,datatype)
With CreateObject("MSXML2.DOMDocument")
.LoadXML "<root />"
.DocumentElement.DataType = datatype
.DocumentElement.nodeTypedValue = rabyt
ToString = Replace(.DocumentElement.text, vbLf, "")
End With
End Function
Function ToSHA1HMAC(sTextToHash, sSharedSecretKey)
Dim asc, enc, hex, bytes, TextToHash, SharedSecretKey
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
bytes = enc.ComputeHash_2((TextToHash))
hex = ToString(bytes,"bin.Hex")
hex = asc.Getbytes_4(hex)
base64 = ToString(hex,"bin.base64")
ToSHA1HMAC = base64
End Function
hashedvalue = ToSHA1HMAC("value","secretkey")
msgbox hashedvalue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment