hashdeep/md5deep (CLI hashing utilities)

Share interesting information or links related to portable apps here.
Post Reply
Message
Author
User avatar
Midas
Posts: 4379
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

hashdeep/md5deep (CLI hashing utilities)

#1 Post by Midas » Sun Jun 24, 2018 1:15 pm

If you do any research into hashing tools you're bound to come across multi-platform md5deep/hashdeep (http://md5deep.sourceforge.net/), regarded as more or less the standard solution for anything related.
md5deep is a set of programs to compute MD5, SHA-1, SHA-256, Tiger, or Whirlpool message digests on an arbitrary number of files. md5deep is similar to the md5sum program found in the GNU Coreutils package, but has [...] additional features...


md5deep is FLOSS (source is on Github) with a somewhat peculiar license blurb:
At the time md5deep was originally written, Mr. Kornblum was a Special Agent with the United States Air Force Office of Special Investigations (AFOSI). As such, the program is considered to be a work of the United States Government. Under 17 USC 105, works of the United States Government are not eligible for copyright protection.


md5deep is composed of a set of 12 different command line executables, each one geared towards a different hashing method and OS bitness. Documentation is rather extensive.

Download md5deep/hashdeep v4.4, released 2014-01-29, from https://github.com/jessek/hashdeep/releases.

As a contribution for the problem I brought to a recent discussion, here's a quick'n'dirty™ script to use md5deep to hash and sidecar any file dropped on it: :wink:

Code: Select all

@ECHO OFF

:: Conditional clause below is a crude detector of OS bitness
:: Allowing for running the corresponding executable
:: Made by Midas, 2018-06-24
IF EXIST "%PROGRAMFILES(x86)%" (SET BOS=64
 ) ELSE (SET BOS=""
 )
MD5Deep%BOS% -bk "%1" > "%~n1.md5"

User avatar
Midas
Posts: 4379
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: CLI hashing script

#2 Post by Midas » Tue Oct 09, 2018 7:07 am

Improving on my own previous solution, here's a hybrid batch script that works in Windows 7 and doesn't require any external utility, only an existing Powershell v4 or newer -- apparently that 'get-filehash' command doesn't work in previous versions. I was lead to this solution from the simple validating instructions in RegistryFinder homepage.

If you create a plain text file named 'shash.cmd' with the following code and drop any other file from the same folder on it, it will create the corresponding hash in a file with the 'md5' extension (alternatively, you can use 'shash filename.ext' at the CLI). I often use such files to validate downloads using Teracopy's shell extension, if an hash is available online (e.g., as in the case of AndroidFileHost.com).

Code: Select all

@ECHO OFF
REM Sidecar MD5 hashing script v0.1 by Midas (http://v.ht/md5PS: 2018-10-08)
POWERSHELL "get-filehash %1 -Algorithm md5 | ForEach-Object { $_.Hash }" > _tmp_
SET /P _hash=<_tmp_
DEL _tmp_
ECHO %_hash% *%~nx1> "%~n1.md5"
Please note that this will also work for SHA1, SHA256, SHA384, and SHA512 if all instances of "md5" in the code above are replaced with the appropriate algorithm string.

PS: I know there are more elegant ways to pass the result of the first command directly to a variable, but I found none simpler than using a temporary file. Suggestions welcome.

Post Reply