Created
August 4, 2016 07:29
-
-
Save vector-sec/f814903b633121d9948ad643f583556f to your computer and use it in GitHub Desktop.
VBScript implementation of SHA1HMAC meeting Duo Security's specifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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