Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Applescript droplet to get the SHA1 checksum' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Applescript droplet to get the SHA1 checksum
Authored by: jordanmd on Jun 13, '10 09:21:06PM
I know this is not AppleScript, but if there are those that want a quick and easy compare and if you're a Terminal fan, I use this code in my $HOME/.bashrc file:

cksha1 ()
{
if [ $# -lt 2 ] ; then
	echo "Usage: cksha1 filepath sha1-sum ..." ;
	echo "       must specify at least one pair of file and checksum." ;
	echo "Exiting." ;
fi

filesha1=`/usr/bin/openssl sha1 $1 | /usr/bin/awk -F"=" '{ print $2 }'` ; 
	if [ $filesha1 == $2 ] ; then 
		echo "** SHA1 matches **" ; 
	else 
		echo " ********** ERROR: SHA1 DOES NOT MATCH **********" ; fi
}

This lets me copy the checksum from the web page where they list it and do the following in Terminal:

$ cksha1 ~/Desktop/Inbox/GoogleChrome.dmg e90cc5b126544dfa9a264a105d49a1824fb8786d
** SHA1 matches **

You can easily do the same for the other common digest format: MD5

ckmd5 ()
{
if [ $# -lt 2 ] ; then
	echo "Usage: ckmd5 filepath md5sum ..." ;
	echo "       must specify at least one pair of file and checksum." ;
	echo "Exiting." ;
fi

filemd5=`/usr/bin/openssl md5 $1 | /usr/bin/awk -F"=" '{ print $2 }'` ; 
	if [ $filemd5 == $2 ] ; then 
		echo "** MD5 matches **" ; 
	else 
		echo " ********** ERROR: MD5 DOES NOT MATCH **********" ; fi
}
With the same sort of results:
$ ckmd5 ~/Desktop/Inbox/GoogleChrome.dmg  520e8730b8d1551db45eb56649473267
** MD5 matches **
This allows you to create other commands that might automate grabbing files and comparing the checksums.

[ Reply to This | # ]