MD5Checker

Discuss and share scripts and script files...
Post Reply
Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

MD5Checker

Post by Stefan »

There are a few scripts dealing with MD5 hashes in this forum section,
but they doesn't work the way i need such an function.

I want to use this workflow:
1. select an file
2. execute script to calculate MD5 hash
3. paste in MD5 hash from an web site
4. an dialog tell you if the hash match
Script_MD5Checker_001b.PNG


So i exploit the other hash scripts to check how this works and create my own script:

First release:

Code: Select all

End ("<curitem>"==""),  "No file selected!";
  $fileContents = ReadFile("<curitem>", "b");
  $FileHash = MD5("$fileContents");
  $origHash = input("Original MD5 Hash",Paste MD5 hash from the web site 
   to check against "<curname>" ,<clipboard>);
  replace $origHash, $origHash, " ";
  $comp = compare($FileHash, $origHash, "i"); 
  IF ($comp!='0') {$result="No"}else{$result="Yes"};
  msg File Hash:  $FileHash<crlf>Original:    $origHash<crlf><crlf>Same: $result;

Long form with comments and improvements:

Code: Select all

/* 
MD5Checker 20091207 , Stefan 

LICENSE:
    This script is free software: you can redistribute and/or modify it.
    This script is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    If your computer implode or your files gets lose, don't blame me, so
    please try this script first with some test files in an virtual machine.
     
Purpose:     
		MD5Checker calculates the MD5 message digest for one file. 
		By comparing the MD5 digest of a file to a value supplied by 
		the original sender, you can make sure that files you download 
		are free from damage and tampering. 

How to use:
	1.) Copy the script below in an file "..\scripts\MD5Checker.xys".
	2.) Then, e.g., add an CTB toolbar button:
		Name: MD5Checker
		Icon: %SystemRoot%\system32\SHELL32.dll /172
		On Click: load MD5Checker;
	3.) Select an file in XY.
	4.) execute this script.
	5.) you are prompted, paste in the original MD5 Hash from the web site.
	6.) click on OK, you will see an message if both hash strings are the same.
*/

// the script:

End ("<curitem>"==""),  "No file selected!"; //check if any file is selected

   $fileContents = ReadFile("<curitem>", "b"); //read file content
   $FileHash = MD5("$fileContents"); //calculate hash from file content

   $origHash = input("Original MD5 Hash","Paste MD5 hash from the web site 
    to check against ""<curname>""" ,<clipboard>); //input copied hash from web page
    //$origHash = "<clipboard>"; //alternative input without using input-box

   replace $origHash, $origHash, " "; //Trim blanks
   $comp = compare($FileHash, $origHash, "i"); //compare both hash-strings case-insensitive
   IF ($comp!='0') {$result="No"}else{$result="Yes"}; //compose output
 
   IF ($result=="No") {
     //Added here the possibility to calculate and copy an hash:
     msg "File Hash:  $FileHash<crlf>Original:    $origHash<crlf><crlf>
     Same: $result<crlf><crlf>Press OK-Button to copy FileHash to clipboard",1;
     copytext $FileHash; //copy calculated FileHash to clipboard
   }else{
     msg "File Hash:  $FileHash<crlf>Original:    $origHash<crlf><crlf>Same: $result"; //output
   }
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY, please test it with test files first.


History:
MD5Checker_20091206.xys - First release
MD5Checker_20091207.xys - 1) compare case-insensitive, thanks atjnjk, 2) spelling mistake side>site, thanks JC, 3) add Get&copy an hash
MD5Checker_20091207.xys


Thanks to the people of this forum for all the great support.
You do not have the required permissions to view the files attached to this post.
Last edited by Stefan on 07 Dec 2009 11:41, edited 6 times in total.

atjnjk
Posts: 32
Joined: 04 Nov 2009 07:03

Re: MD5Checker

Post by atjnjk »

Thank you for your script.
IMHO, I think you should change
$comp = compare($FileHash, $origHash);
to
$comp = compare($FileHash, $origHash, "i");
As sometimes, hashes are given with capital letters.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: MD5Checker

Post by Stefan »

atjnjk wrote:to
$comp = compare($FileHash, $origHash, "i");
You're right, thank you. Corrected.

Post Reply