#211464 - 2016-05-11 10:12 AM
Re: vbscript MD5 conversion issues
[Re: Lonkero]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
I've tried to get around the file size limit but to no avail. Instead I've added SHA256, SHA384 en SHA512 functions :P
Function SHA256($strFileName)
Dim $objXML, $objXEL, $objSHA256, $objStream, $BinaryFile
$objStream = CreateObject("ADODB.Stream")
$objStream.Type = 1
$objStream.Open
$objStream.LoadFromFile($strFileName)
$BinaryFile = $objStream.Read
$objStream.Close
$objStream = ""
$objSHA256 = CreateObject("System.Security.Cryptography.SHA256Managed")
$=$objSHA256.ComputeHash_2($BinaryFile)
$objXML = CreateObject("MSXML2.DOMDocument")
$objXEL = $objXML.CreateElement("tmp")
$objXEL.DataType = "bin.hex"
$objXEL.NodeTypedValue = $objSHA256.Hash
$SHA256 = $objXEL.Text
EndFunction
? "SHA256: "+SHA256("D:\Firefox Setup 46.0.1.exe")
Function SHA384($strFileName)
Dim $objXML, $objXEL, $objSHA384, $objStream, $BinaryFile
$objStream = CreateObject("ADODB.Stream")
$objStream.Type = 1
$objStream.Open
$objStream.LoadFromFile($strFileName)
$BinaryFile = $objStream.Read
$objStream.Close
$objStream = ""
$objSHA384 = CreateObject("System.Security.Cryptography.SHA384Managed")
$=$objSHA384.ComputeHash_2($BinaryFile)
$objXML = CreateObject("MSXML2.DOMDocument")
$objXEL = $objXML.CreateElement("tmp")
$objXEL.DataType = "bin.hex"
$objXEL.NodeTypedValue = $objSHA384.Hash
$SHA384 = $objXEL.Text
EndFunction
? "SHA384: "+SHA384("D:\Firefox Setup 46.0.1.exe")
Function SHA512($strFileName)
Dim $objXML, $objXEL, $objSHA512, $objStream, $BinaryFile
$objStream = CreateObject("ADODB.Stream")
$objStream.Type = 1
$objStream.Open
$objStream.LoadFromFile($strFileName)
$BinaryFile = $objStream.Read
$objStream.Close
$objStream = ""
$objSHA512 = CreateObject("System.Security.Cryptography.SHA512Managed")
$=$objSHA512.ComputeHash_2($BinaryFile)
$objXML = CreateObject("MSXML2.DOMDocument")
$objXEL = $objXML.CreateElement("tmp")
$objXEL.DataType = "bin.hex"
$objXEL.NodeTypedValue = $objSHA512.Hash
$SHA512 = $objXEL.Text
EndFunction
? "SHA512: "+SHA512("D:\Firefox Setup 46.0.1.exe")
|
Top
|
|
|
|
#211465 - 2016-05-11 10:18 AM
Re: vbscript MD5 conversion issues
[Re: Arend_]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
And I've just combined all in 1 function, enjoy
Function Hash($strFileName, optional $strHashType)
Dim $objXML, $objXEL, $objHash, $objStream, $BinaryFile
$objStream = CreateObject("ADODB.Stream")
$objStream.Type = 1
$objStream.Open
$objStream.LoadFromFile($strFileName)
$BinaryFile = $objStream.Read
$objStream.Close
$objStream = ""
Select
Case $strHashType = "MD5"
$objHash = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
Case $strHashType = "SHA1"
$objHash = CreateObject("System.Security.Cryptography.SHA1CryptoServiceProvider")
Case $strHashType = "SHA256"
$objHash = CreateObject("System.Security.Cryptography.SHA256Managed")
Case $strHashType = "SHA384"
$objHash = CreateObject("System.Security.Cryptography.SHA384Managed")
Case $strHashType = "SHA512"
$objHash = CreateObject("System.Security.Cryptography.SHA512Managed")
Case 1
$objHash = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
EndSelect
$RC=$objHash.ComputeHash_2($BinaryFile)
$objXML = CreateObject("MSXML2.DOMDocument")
$objXEL = $objXML.CreateElement("tmp")
$objXEL.DataType = "bin.hex"
$objXEL.NodeTypedValue = $objHash.Hash
$Hash = $objXEL.Text
EndFunction
? "Hash: "+Hash("D:\Firefox Setup 46.0.1.exe", "md5")
|
Top
|
|
|
|
#211475 - 2016-05-12 05:19 PM
Re: vbscript MD5 conversion issues
[Re: Arend_]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Well I have figured out why the size matters (Yes ladies, it does ). Apparently it is a memory limit. To fix this, you have to feed the bytes to the System.Security.Cryptography object in blocks using the .TransFormBlocks and eventually the .TransFormFinalBlocks property of the object before using the ComputeHash property. The only problem I see is to get the stream reader to split it up in chucks of less then 200 MB. If I get more time I'll try to sort it out.
|
Top
|
|
|
|
#211477 - 2016-05-13 11:31 AM
Re: vbscript MD5 conversion issues
[Re: Arend_]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Well, even using TransFormBlock it still has the size problem. Apparently the size problem lies within the System.Security.Cryptography.MD5CryptoServiceProvider.
Function MD5($strFileName)
Dim $adTypeBinary, $objStream, $objXML, $objXEL, $objMD5, $i, $intFinalBlock, $BinaryFile
$adTypeBinary = 1
$objStream = CreateObject("ADODB.Stream")
$objStream.Type = $adTypeBinary
$objStream.Open
$objStream.LoadFromFile($strFileName)
$objMD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
$objMD5.Initialize
$BinaryFile = $objStream.Read
For $i=0 to $objStream.Size Step 31744
$=$objMD5.TransformBlock($BinaryFile, $i, 31744, $BinaryFile, $i)
If ($objStream.Size -$i) < 31744
$intFinalBlock = ($objStream.Size -$i)
$=$objMD5.TransformFinalBlock($BinaryFile, $i, $intFinalBlock)
EndIf
Next
$objXML = CreateObject("MSXML2.DOMDocument")
$objXEL = $objXML.CreateElement("tmp")
$objXEL.DataType = "bin.hex"
$objXEL.NodeTypedValue = $objMD5.Hash
$MD5 = $objXEL.Text
$objStream.Close
$objStream = ""
EndFunction
The last option is to read the Stream in chunks and feed the chunks to TransformBlock.
|
Top
|
|
|
|
#211486 - 2016-05-13 04:10 PM
Re: vbscript MD5 conversion issues
[Re: ShaneEP]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Thanks Couldn't be done without Allen's initial work, thanks Allen!
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 370 anonymous users online.
|
|
|