Thursday, July 09, 2009

How to compute MD-5 and SHA-1 hash of files from Eclipse

Often I need to calculate MD-5 and/or SHA-1 hash of files in my workspace. I find it annoying to leave Eclipse and run command line tool every time I have to know these hashes.

Here is a trick I devised to get this done quickly without leaving the IDE. This is for Eclipse running on Windows XP but, can be applied for other operating systems too.

1. Download any free command line tool (or roll your own) to compute hashes. I chose Microsoft's free utility called FCIV (File Checksum Integrity Verifier).

2. Extract FCIV tool at a convenient location e.g. c:\fciv\fciv.exe

3. Configure "External Tools" in Eclipse (go to Menu -> Run ->External tools -> Open External tools Dialogue) for FCIV as shown in the diagram below. You can organize the tool in your "favorites" for easy access.




4. Configure a shortcut key to launch FCIV tool.
Go to Menu -> Window -> Prefrences -> General -> Keys and filter for "external". Create a shortcut key combination (e.g. Alt+L) for "Run Last Launched External Tool". Use this dialogue to configure a shortcut for "External tool..." too, e.g. Alt+R.



This is all that is needed to configure the FCIV tool.

5. Now, select a resource in your workspace and press "Alt+R". This will bring up the "External Tools" dialogue.

6. Select the FCIV tool from the dialogue.

7. This will print both MD5 and SHA-1 of the selected file in the console window at the bottom of Eclipse IDE.

8. For computing hashes of next file, just press shortcut "Alt+L".

Tip:
To compute hashes of all the files in a directory, select at directory and use the shortcut "Alt+L".

Hope it helps.