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
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
}
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© an hash
Thanks to the people of this forum for all the great support.
XYplorer Beta Club