I have been seeing a number of people looking for ways to perform MD5 calculations using AutoIt. This was a clue to me write and article about it.
Introducing MD5
MD5 is a mathematical formula that generates a 128-bit value for a text string or a file. The value is always represented as a string of 32 numbers and letters ranging from 0 to F (also known as the hexadecimal number set).
The two primary uses for MD5 today are to ensure a file has downloaded correctly from the Internet and to record passwords. To use MD5 to check for proper Internet downloads, the publisher of the file will calculate an MD5 checksum on the file that he is making available to download. He will then publish that checksum along with the file. When a user downloads the file, they can then generate an MD5 checksum on the file and compare it to the one generated by the publisher. If the two checksums are the same, then the file was downloaded correctly. Otherwise, the file may be damaged.
To use MD5 to save passwords, a system will receive a password and genereate an MD5 checksum for the password. It will then record this password. The next time someone tries to log into the system, it will retrieve the password and generate a second MD5 checksum. If the stored checksum and the new checksum are the same, then the system knows the user entered the same correct password. The major benefit that is realized from doing this is the encryption of the password for storage. If someone were to get the stored password file, they would not be able to reverse engineer the original passwords.
MD5 in AutoIt
There is no built-in way of generating MD5 checksums within AutoIt but there have been a number of people on the AutoIt Forums that have provided code and work arounds. There are three primary ways to generate MD5 checksums:
- Call an external application
- Use an AutoIt plugin
- Use native AutoIt code
Each has its pros & cons and each has its use and purpose. Let’s take a look at each.
Call an External Application
SolidSnake on the AutoIt Forums has generated two UDFs called _StringHash() and _FileHash(). (If you aren’t sure about UDFs, then please check out AutoIt UDF’s; A Lot of Power in One Line.)
In SolidSnake’s UDFs, he uses the open source applications md5deep to generate the MD5 checksum for either a text string or a file. The md5deep.exe file from this source is required to be located in the same folder as your AutoIt script or the script will fail.
Here is a sample AutoIt script that uses this method to get the MD5 hash for a line of text and a file.
;MD5 checksum using external application #Include <StringHash.au3> #Include <FileHash.au3> Dim $InputString = "Visit http://www.DailyCupOfTech.com" Dim $InputFile = @WindowsDir & "\winhlp32.exe" Dim $StringMD5 Dim $FileMD5 $StringMD5 = _StringHash($InputString,0) $FileMD5 = _FileHash($InputFile,0) MsgBox(0,"MD5 Results","String = " & $InputString & @CRLF & "String MD5 = " & $StringMD5 & @CRLF & @CRLF & "File = " & $InputFile & @CRLF & "File MD5 = " & $FileMD5)
Download this code: MD5-EA.au3
Use an AutoIt Plugin
The second method used to generate an MD5 checksum was developed by JSThePatriot. He created an MD5 plugin for AutoIt to perform the task.
A plugin is a file or program that can extend the functionality of the program. This is exactly what JSThePatriot’s plugin does. It allows you to create both string and file checksums.
Here is a sample AutoIt script that should generate results very similar to the ones in the first script. Please note that you need to download JSThePatriot’s plugin and ensure that it is in the same directory as your script otherwise it will not work.
;MD5 checksum using plugin #compiler_plugin_funcs = MD5Hash Dim $MD5Plugin Dim $InputString = "Visit http://www.DailyCupOfTech.com" Dim $InputFile = @WindowsDir & "\winhlp32.exe" Dim $StringMD5 Dim $FileMD5 $MD5Plugin = PluginOpen(@ScriptDir & "\MD5Hash.dll") $StringMD5 = MD5Hash($InputString,2,True) $FileMD5 = MD5Hash($InputFile,1,True) MsgBox(0,"MD5 Results","String = " & $InputString & @CRLF & "String MD5 = " & $StringMD5 & @CRLF & @CRLF & "File = " & $InputFile & @CRLF & "File MD5 = " & $FileMD5) PluginClose($MD5Plugin)
Download this code: MD5-PI.au3
Use Native AutoIt Code
The final way that you can generate a checksum is by using native AutoIt code. SvenP created an MD5 UDF that will generate an MD5 checksum for any string that it is given.
Please note that there are two potential issues with this type of MD5 checksum generation. One, it can be extremely slow and, two, it is limited to strings and cannot generate checksums for files.
This code will demonstrate how you can get a string’s MD5 checksum.
;MD5 checksum using native AutoIt Code #Include <MD5.au3> Dim $InputString = "Visit http://www.DailyCupOfTech.com" Dim $InputFile = @WindowsDir & "\winhlp32.exe" Dim $StringMD5 Dim $FileMD5 $StringMD5 = MD5($InputString) $FileMD5 = "Unavailable via this method" MsgBox(0,"MD5 Results","String = " & $InputString & @CRLF & "String MD5 = " & $StringMD5 & @CRLF & @CRLF & "File = " & $InputFile & @CRLF & "File MD5 = " & $FileMD5)
Download this code: MD5-AI.au3
Conclusion
From these examples, it is apparent that you can create MD5 checksums for text strings using only native AutoIt code. But, if you want better performance and the ability to create MD5 checksums for files, then you are going to need a little outside help from either a third-party application or an AutoIt plugin.
Hopefully, this was a helpful article. I look forward to your feedback and any suggestions or updates.
| Trackback link - http://www.dailycupoftech.com/perform-md5-using-autoit/trackback/ |
|


March 28th, 2007 at 5:18 pm
Installing Ubuntu Desktop Part 3 Is Internet Explorer 7 Spying on Me? Linux from Scratch, The Saga Modify Every Computer on the Network Monitor Your Website With Google Alerts Multiple Computer Setup Perform MD5 Using AutoIt Providing User Feedback In AutoIt Recovering Your Lost Passwords Reducing the USB Threat Remote Control Mac From Windows Setting Up FTP Access in FreeNAS Spam Filter Busters Stop Applications From Running
April 27th, 2007 at 12:22 pm
brute-force attacking to the cracking system. Table benchmark tests: An Online Resources I have been seeing a number of people looking for ways to perform MD5 calculations using AutoIt. This was a clue to me write and article about it. Introducing MD5 An Online Resources 14.4 DES, MD5, and Crypt Parts rewritten and updated by Bill Swingle. Every user on a UNIX system has a password associated with their account. It seems obvious that these passwords need to be An Online Resources
April 23rd, 2008 at 3:12 am
how do i return to normal string?
April 20th, 2009 at 12:56 am
*facepalm*
You can’t return a normal string. An MD5 hash is just a code you can use to check to see if one string is close to an original. The MD5 codes will eventually repeat, so there’s a 1 in 34030000000000000000000000000000000000 chance that two completely different files will have the same MD5 hash. So any one MD5 hash has an infinite number of strings it could have been originally.
It’s simple (read:unsafe) one-way encryption, like if you want to store a password — save the MD5 hash, then check it every time someone opens your program.