SHA-1 Hash of an Entire Folder Structure
Can anyone recommend a program / utility that I can point to a folder and it generates a SHA-1 hash of all contents? I'm familiar with using Hashcalc which works very well with single files... a fallback option I have is to take a zip archive the aforementioned folder and then hash the archive... but I'm hoping to not have to do that. Kind regards, Dave
June 7th, 2010 8:13pm

how much large is folder content?http://en-us.sysadmins.lv
Free Windows Admin Tool Kit Click here and download it now
June 8th, 2010 9:56am

Hi, It's only about 4MB... but it consists of about 100 files in about twenty folders. Regards, Dave
June 8th, 2010 10:04am

would PowerShell script fine for you?http://en-us.sysadmins.lv
Free Windows Admin Tool Kit Click here and download it now
June 8th, 2010 10:12am

Hi, I have written a small console program that compute the hash of the content of a directory. It will explore it recursively and it uses the lexicographical order on names for sorting its content before performing the hash computation. I have implemented SHA-1, SHA-256, SHA-384 and SHA-512. It can be called as follows : DirHash.exe Path [Algorithm] . The second parameter is optional: by defaut, SHA-1 is used but you can specify other hash algorithms by setting the second parameter to SHA256, SHA384 or SHA512. You can get the binary using the following link : http://www.idrix.fr/Root/Samples/DirHash.zip I hope this will help. Cheers -- Mounir IDRASSI IDRIX http://www.idrix.fr
June 8th, 2010 5:56pm

Vadims, Yes, PowerShell would be an excellent solution. Regards, Dave
Free Windows Admin Tool Kit Click here and download it now
June 8th, 2010 8:48pm

Mounir, Many thanks - I've had a very quick look at your utility and it seems very simple (that's a good thing) in execution. I'll do a little further testing but I think it does exactly what I want. Kind regards, Dave
June 8th, 2010 8:50pm

How about fciv.exe (http://support.microsoft.com/kb/841290)?
Free Windows Admin Tool Kit Click here and download it now
June 9th, 2010 6:08pm

Hello Chip! Sorry for my late response. Here is PowerShell example: function Get-FolderHash ($folder) { dir $folder -Recurse | ?{!$_.psiscontainer} | %{[Byte[]]$contents += [System.IO.File]::ReadAllBytes($_.fullname)} $hasher = [System.Security.Cryptography.SHA1]::Create() [string]::Join("",$($hasher.ComputeHash($contents) | %{"{0:x2}" -f $_})) } copy and paste this code to PowerShell console and type: Get-FolderHash "C:\CustomFolder" where C:\CustomFolder is your folder (and subfolders) against which hash is computed. Martin: as far as I remember, FCIV cannot create single hash for multiple files. FCIV just creates a single hash for each file and writes it to XML file. http://en-us.sysadmins.lv
June 9th, 2010 6:24pm

Many thanks Vadims. I just tested the script (on Windows 7 x86) and whilst it seemed to run OK there was no output generated... I'm not sure what I should be expecting (as in does it output the hash to the console)? Forgive me my ignorance regarding PowerShell! I tried running this as you said by copying and pasting into the PowerShell prompt, I also tried by saving the text to a file called Get-FolderHash.ps1 and executing this followed by the folder name. I really do apologise for being a PowerShell novice... what is the easiest way to run this as a "batch file"? Kind regards, Dave
Free Windows Admin Tool Kit Click here and download it now
June 9th, 2010 11:08pm

Martin: as far as I remember, FCIV cannot create single hash for multiple files. FCIV just creates a single hash for each file and writes it to XML file. http://en-us.sysadmins.lv Yes that is correct, looks like I misunderstood the question. Martin
June 10th, 2010 9:20am

open PowerShell console and type: New-Item $Profile -ItemType File -force notepad $profile in opened notepad window copy and paste this function. Save notepad document. Re-open PowerShell console. Each time you want to calculate the hash for a folder you need to type only the following command: Get-FolderHash "C:\CustomFolder" where C:\CustomFolder is your folder (and subfolders) against which hash is computed. When you saved the code into PS1 file and executed you just loaded a function. To get an output, you need to call this function.http://en-us.sysadmins.lv
Free Windows Admin Tool Kit Click here and download it now
June 10th, 2010 2:23pm

Vadims, I've done as instructed, but get the following results... ######################################################################## PS C:\> New-Item $Profile -ItemType File -force Directory: C:\Users\me\Documents\WindowsPowerShell Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 10/06/2010 17:59 0 Microsoft.PowerShell_profile.ps1 PS C:\> notepad $profile >>>>>>>> I then pasted in the code and saved it to the default location <<<<<<<<<<<<< PS C:\> get-folderhash "C:\Data" The term 'get-folderhash' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:15 + get-folderhash <<<< "C:\Data" + CategoryInfo : ObjectNotFound: (get-folderhash:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException ############################################################################## I do apologise for being very weak on PowerShell, but this all seems very messy; is there really no easy way to just run a "script" and pass the folder as an "argument"? Kind regards, Dave
June 10th, 2010 8:11pm

If you have saved the code above into Microsoft.PowerShell_profile.ps1 file, you need to reopen PowerShell console.http://en-us.sysadmins.lv
Free Windows Admin Tool Kit Click here and download it now
June 10th, 2010 11:17pm

Got it... finally! Thanks for your patience, Dave
June 11th, 2010 10:16am

Hi Mounir IDRASSI, Thanks for this tool. This is exactly what I was looking for. I visited your web site and found that you provide source code for some tools as well. Could you please provide source for this tool as well? I would like to integrate this approach in one of my projects. Thanks, Sourabh Bhandari
Free Windows Admin Tool Kit Click here and download it now
December 22nd, 2010 6:02am

Hi, I have put the source file at the following link : http://www.idrix.fr/Root/Samples/DirHash.cpp . It uses OpenSSL for the hashing algorithms (especially SHA-256, SHA-384 and SHA-512) in order to support all version of Windows (from Windows 2000) without relying on the presence of a specific CSP. I have also put the full VC 2008 project that includes OpenSSL headers and its static library. You can get it here : http://www.idrix.fr/Root/Samples/DirHash_src.zip I hope this will help. Cheers, -- Mounir IDRASSI IDRIX http://www.idrix.frMounir IDRASSI IDRIX http://www.idrix.fr
December 22nd, 2010 7:24am

Hi Mounir, Many thanks for the source code. This is exactly what I was looking for. Best regards, -Sourabh Bhandari
Free Windows Admin Tool Kit Click here and download it now
December 23rd, 2010 1:13am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics