Post

Calculate a file hash without 3rd party tools on Windows and Linux.

If you need to generate a hash of a file (e.g. MD5, SHA256 etc) then there are numerous 3rd party tools that you can download but if you are restricted to only built in tools or don’t need to do this often enough to install something then there are built in OS tools for Windows and Linux that can be used.

Windows

For Windows there is “certUtil” which can be used from the command prompt console with  the “-hashfile” option to generate a hash for a supplied file:

1
CertUtil [Options] -hashfile filePath [HashAlgorithm]

The [HashAlgorithm] options are MD2, MD4, MD5, SHA1 (default), SHA256, SHA384 and SHA512.

For example to get an MD5 hash of a file use:

1
CertUtil -hashfile C:\ExampleFile1.txt MD5

More documentation for CertUtil can be seen here.

For those with access to PowerShell v4  and above (Windows 8.1 & Win Server 2012 R2) you can use the built in commandlet called get-filehash like this:

1
Get-FileHash C:\ExampleFile1.txt  -Algorithm MD5 | Format-List

The algorithms supported are SHA1, SHA256 (default), SHA384, SHA512, MACTripleDES, MD5 & RIPEMD160.

For Powershell versions prior to V4 there are numerous scripts available on the web that will work out the hash for you using various methods.

Linux

For Linux use the correct  hashalgorithm_SUM command in the terminal for the algorithm you are looking for, i.e. for an MD5 hash use _md5sum or for SHA512 hash use sha512sum.

For example:

1
2
3
md5sum /home/bob/Documents/ExampleFile1.txt 
sha1sum /home/bob/Documents/ExampleFile1.txt
sha512sum /home/bob/Documents/ExampleFile1.txt
This post is licensed under CC BY 4.0 by the author.