Vbscript string to MD5 hexidecimal hash

Experts:

I have a need to script out the hashing of a string to MD5 to do a comparison against a hashed value in a database.  I do not want to have to use any external EXE to perform this action and VBscript/Jscript are the only languages I can use on this particular project.

I've managed to find a lot of information on the MD5 hashing and classes available in .NET 3.5, but have yet been able to perform the hash and view the hexidecimal output.

Here is a link to MSDN's document on MD5 class:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5cryptoserviceprovider.aspx

Any ideas?
LVL 12
piattndAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sr75Connect With a Mentor Commented:
Here is a link to the file and it also has some instructions on how to use it:

http://www.xstandard.com/en/documentation/xmd5/


WScript.Echo "Comparing 2 strings:"
strString = "Meet John Doe"
WScript.Echo "MD5 Checksum for """ & strString _
           & """: " & GetStringCheckSum( strString )
strString = "meet John Doe"
WScript.Echo "MD5 Checksum for """ & strString _
           & """: " & GetStringCheckSum( strString )
WScript.Echo
WScript.Echo "Comparing 2 files:"
strFile1 = "C:\WINDOWS\System32\wmpcore.dll"
strFile2 = "C:\WINDOWS\System32\dllcache\wmpcore.dll"
WScript.Echo "MD5 Checksum for " & strFile1 _
           & ":          " & GetFileCheckSum( strFile1 )
WScript.Echo "MD5 Checksum for " & strFile2 _
           & ": " & GetFileCheckSum( strFile2 )



Function GetFileCheckSum( myFile )
' This function uses X-standards.com's X-MD5 component to calculate
' the MD5 checksum of a file.
'
' Argument:
' myFile [string] the file name whose checksum is to be calculated
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' The X-MD5 component is available at:
' http://www.xstandard.com/page.asp?p=C8AACBA3-702F-4BF0-894A-B6679AA949E6
' For more information on available functionality read:
' http://www.xstandard.com/printer-friendly.asp?id=44AFBB03-EDC1-49FE-94CC-333AE728331E
    Dim objMD5
    Set objMD5 = CreateObject( "XStandard.MD5" )
    GetFileCheckSum = objMD5.GetCheckSumFromFile( myFile )
    Set objMD5 = Nothing
End Function


Function GetStringCheckSum( myString )
' This function uses X-standards.com's X-MD5 component to calculate
' the MD5 checksum of a string.
'
' Argument:
' myString [string] the string whose checksum is to be calculated
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' The X-MD5 component is available at:
' http://www.xstandard.com/page.asp?p=C8AACBA3-702F-4BF0-894A-B6679AA949E6
' For more information on available functionality read:
' http://www.xstandard.com/printer-friendly.asp?id=44AFBB03-EDC1-49FE-94CC-333AE728331E
    Dim objMD5
    Set objMD5 = CreateObject( "XStandard.MD5" )
    GetStringCheckSum = objMD5.GetCheckSumFromString( myString )
    Set objMD5 = Nothing
End Function

Open in new window

0
 
sr75Commented:
Can you use a library??  I use a library I found called XMD5.dll.  It works pretty good in my scripts.  
0
 
piattndAuthor Commented:
I might be able to register/unregister it.  Can you throw me the DLL and instructions on how you used it?
0
 
piattndAuthor Commented:
Thank you very much for the thorough VBS code example and the DLL.  I was able to take what you gave and turn it into exactly what I need!
0
All Courses

From novice to tech pro — start learning today.