I found a vbscript that creates a MD5 hash but have not had luck converting it to kixtart.

Here is the original vbscript code that does work:
{edit: had to change code tag to quotes on the vbscript code... board didnt like it}

 Quote:


'MD5=151D5E94EE1197E3A3AD8E8089A73884
spath="C:\Downloads\Firefox Setup 46.0.1.exe"
wscript.echo bytesToHex(md5hashBytes(GetBytes(sPath)))

function md5hashBytes(aBytes)
Dim MD5
set MD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")

MD5.Initialize()
'Note you MUST use computehash_2 to get the correct version of this method, and the bytes MUST be double wrapped in brackets to ensure they get passed in correctly.
md5hashBytes = MD5.ComputeHash_2( (aBytes) )
end function

function stringToUTFBytes(aString)
Dim UTF8
Set UTF8 = CreateObject("System.Text.UTF8Encoding")
stringToUTFBytes = UTF8.GetBytes_4(aString)
end function

function bytesToHex(aBytes)
dim hexStr, x
for x=1 to lenb(aBytes)
hexStr= hex(ascb(midb( (aBytes),x,1)))
if len(hexStr)=1 then hexStr="0" & hexStr
bytesToHex=bytesToHex & hexStr
next
end function

Function BytesToBase64(varBytes)
With CreateObject("MSXML2.DomDocument").CreateElement("b64")
.dataType = "bin.base64"
.nodeTypedValue = varBytes
BytesToBase64 = .Text
End With
End Function

Function GetBytes(sPath)
With CreateObject("Adodb.Stream")
.Type = 1 ' adTypeBinary
.Open
.LoadFromFile sPath
.Position = 0
GetBytes = .Read
.Close
End With
End Function


My goal was to create a all in one function to spit out the MD5 hash. I am getting results but they are not correct. What's interesting is, the first few digits are correct although there are 0's in between the values. Once the first few digits are reached, nothing else match the rest of the hash. There were a few vbscript specific functions that we do not have in kix that I recreated using the scriptcontrol. I was using dectohex but switched to the hex function in hopes it mattered, it didnt.

 Code:
  dim $sPath, $ado, $bytes, $MD5, $MD5hashbytes, $x, $hexstring, $bytestohex
  $Spath="C:\Downloads\Firefox Setup 46.0.1.exe"
  $ADO=createobject("Adodb.Stream")
  $ADO.Type=1 ; adTypeBindar
  $ADO.Open
  $ADO.LoadfromFile($Spath)
  $ADO.position=0
  $Bytes=$ADO.Read
  $ADO.close
  $MD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
  $MD5.Initialize()
  ;Note you MUST use computehash_2 to get the correct version of this method, and the bytes MUST be double wrapped in brackets to ensure they get passed in correctly.
  $md5hashBytes = $MD5.ComputeHash_2( ($Bytes) )
  for $x=1 to lenb($md5hashBytes)
    $hexStr= right("0" + hex(ascb(midb( ($md5hashBytes),$x,1))),2)
	? $hexstr
    $bytesToHex=$bytesToHex + $hexStr
  next
  
  ? $BytestoHex
  
Function ASCB($string)
  Dim $sc
  $sc = CreateObject("ScriptControl")
  $sc.Language = "VBScript"
  $ASCB = $sc.Eval('ASCB("'+ $String + '")')
EndFunction  

Function MidB($string, $start, $length)
  Dim $sc
  $sc = CreateObject("ScriptControl")
  $sc.Language = "VBScript"
  $MidB = $sc.Eval('MIDB("'+ $string + '",' + $Start + ',' + $length +  ')')
EndFunction  

Function LenB($string)
  Dim $sc
  $sc = CreateObject("ScriptControl")
  $sc.Language = "VBScript"
  $LenB = $sc.Eval('LenB("'+ $String + '")')
EndFunction

Function Hex($Number)
  Dim $sc
  $sc = CreateObject("ScriptControl")
  $sc.Language = "VBScript"
  $Hex = $sc.Eval('Hex('+ $Number + ')')
EndFunction




Any ideas/suggestions?


Edited by Allen (2016-05-09 04:16 PM)