Advertisement
ibi

SHA1 Encoding in VBScript

ibi
Jun 24th, 2016
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WScript.Echo getSHA1("myteststring")
  2.  
  3. Function getSHA1(instr)
  4.     Dim asc, enc, bytes, outstr, pos
  5.  
  6.     '.NET 1.1 (and higher) objects
  7.     Set asc = CreateObject("System.Text.UTF8Encoding")
  8.     Set enc = CreateObject("System.Security.Cryptography.SHA1CryptoServiceProvider")
  9.  
  10.     'Convert the string to a byte array and hash it
  11.     bytes = asc.GetBytes_4(instr)
  12.     bytes = enc.ComputeHash_2((bytes))
  13.  
  14.     getSHA1 = ""
  15.  
  16.     'Convert the byte array to a hex string
  17.     For pos = 1 To Lenb(bytes)
  18.         getSHA1 = getSHA1 & LCase(Right("0" & Hex(Ascb(Midb(bytes, pos, 1))), 2))
  19.     Next
  20. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement