- Get File Hash Checksum (MD5, SHA-256) via Right-click Menu
- How to get file hash checksum in Windows
- Get File Hash Checksum via the Right-click Menu in Windows
- Using PowerShell
- Integrate the command to the right-click menu
- Using Certutil.exe with VBScript
- HashMyFiles utility from NirSoft
- Using 7-Zip
- Using HashTools from Binary Fortress
- How to compute hash of a large file chunk?
- 5 Answers 5
- Get File hashes using Windows PowerShell
- Get File hashes using Windows PowerShell
- CertUtil
- Closing Words
Get File Hash Checksum (MD5, SHA-256) via Right-click Menu
Hashing means taking an input string of any length and giving out an output of a fixed length. Using the cryptographic hashing algorithm — e.g., MD5, SHA-256, SHA-384, you can verify if two files are identical or not. The checksum is a hash value used for performing data integrity checks on files. It’s a kind of signature for a file.
When you download large files from the internet such as the Windows 10 ISO images, there are chances that the file gets corrupt or a few bits lost due to inconsistent connection or other factors. Hash verification is the best way to compare the two hashes – source file on a website or server versus the downloaded copy.
Many software vendors put up the hash for file downloads on their site. You might have seen in torrent sites that a hash value usually accompanies the download link.
Also, the hash checksum comparison is an excellent way to identify duplicate files in a computer or compare two folders.
In this article, let’s see how to get the cryptographic hash using MD5, SHA-256, SHA-384 algorithms using various methods, and how to integrate the functionality into the context menu.
How to get file hash checksum in Windows
Get File Hash Checksum via the Right-click Menu in Windows
Using PowerShell
Using Windows PowerShell ( powershell.exe ), you can quickly get the file hash with a single command-line. Here is the command-line example:
This outputs the file hash (by default, it uses the SHA256 algorithm) as shown below:
To use any other algorithm — e.g., SHA384, you can add the -Algorithm SHA384 parameter to the above command-line.
The acceptable values for the -Algorithm parameter are:
- SHA1
- SHA256
- SHA384
- SHA512
- MD5
Copy to the clipboard
To copy the output to the clipboard, pipe the output to the clip command, as below:
Integrate the command to the right-click menu
To add the PowerShell command to the right-click menu for files, here is a .reg file:
- Copy the above lines to Notepad and make a .reg file. For more information, see the article How to create and use .reg files.
- Double-click the .reg file to apply the contents to the registry.
- Now, right-click on a file and click Get File Hash command in the context menu.
The command launches PowerShell, which in turn generates the file hash and copies it to the clipboard automatically.
To remove the context menu option you added, use this undo .reg file
Using Certutil.exe with VBScript
Certutil.exe is a built-in command-line program that is installed as part of Certificate Services. You can use Certutil.exe to compute file checksum using various hashing algorithms. The following command-line syntax is to be used to calculate the SHA256 checksum of a file using Certutil.exe from a Command Prompt window.
If you want to implement Certutil.exe in your right-click menu, here is a VBScript that exactly does it.
- Copy the following VBScript code to Notepad.
- Save the file with .vbs extension – e.g., get-hash-certutil.vbs in a permanent folder.
- Double-click the file to run it.
- In the input box that appears, type ADD and click OK.
It adds the Get File Hash command in the context menu.
Clicking on the menu item computes the SHA256 hash and copies it to the Clipboard automatically.
Open Notepad and paste the file hash stored in the clipboard.
Note: To remove the context menu entry, double-click the file to run it. Then, type REMOVE and click OK.
The above script uses the built-in certutil.exe to generate file hash, by running the command and redirecting its output to the clipboard using Clip.exe :
This is how the output will look like when running it from Command Prompt.
Certutil.exe supports the MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512 hashing algorithms.
Another way to get the file hash via context menu is by using a third-party utility like HashMyFiles.
HashMyFiles utility from NirSoft
HashMyFiles is small utility from Nirsoft that allows you to calculate the MD5 and SHA1 hashes of one or more files in your system. You can easily copy the MD5/SHA1 hashes list into the clipboard, or save them into text/HTML/XML file. HashMyFiles can also be launched from the context menu of Windows Explorer, and display the MD5, SHA256, SHA384, SHA512 hashes of the selected file or folder.
From the Options menu, click Enable Explorer Context Menu option to enable it. It adds the HashMyFiles option to the context menu for files and folders.
Download HashMyFiles from Nirsoft.net
Using 7-Zip
The popular compression utility 7-Zip has a feature that can compute the CRC or SHA checksums via the right-click menu. 7-Zip is a widely used software and it’s most likely that you may have installed it on your computer.
In 7-Zip setup doesn’t enable the option already, you can turn it on by clicking the Tools menu, clicking Options and enabling the CRC SHA > option under the Context menu items: listing. Click OK to save your setting.
Then, all you need to do is right-click on a file, click CRC SHA and then select a hashing algorithm such as CRC-32, CRC-64, SHA-1, SHA-256 from the sub-menu. To select all of the above hashing algorithms (and BLAKE2 algorithm in addition), click the asterisk (*) option.
The checksum information is presented in a separate dialog.
You can select the items and press Ctrl + C on your keyboard to copy it to the clipboard.
Using HashTools from Binary Fortress
HashTools by Binary Fortress Software computes and checks hashes with just one click! Supports CRC32, MD5, SHA1, SHA256, SHA384, SHA512 and SFV’s, as well as integration into the Windows Explorer context menu for one-click access.
Install HashTools or run the portable edition or the tool. Click on the Options button shown with the gears icon, and click Add to Windows Context Menus.
Right-click on a file or a set of files, and click Hash with HashTools in the context menu.
This launches the HashTools program and adds the selected file(s) to the list. Next, click on a hashing algorithm (e.g., CRC, MD5, SHA1, SHA256, etc) to generate the hash checksum for the files.
Do you know any other tool or method to calculate file hash? Let’s know in the Comments section below.
How to compute hash of a large file chunk?
I want to be able to compute the hashes of arbitrarily sized file chunks of a file in C#.
eg: Compute the hash of the 3rd gigabyte in 4gb file.
The main problem is that I don’t want to load the entire file at memory, as there could be several files and the offsets could be quite arbitrary.
AFAIK, the HashAlgorithm.ComputeHash allows me to either use a byte buffer, of a stream. The stream would allow me to compute the hash efficiently, but for the entire file, not just for a specific chunk.
I was thinking to create aan alternate FileStream object and pass it to ComputeHash, where I would overload the FileStream methods and have read only for a certain chunk in a file.
Is there a better solution than this, preferably using the built in C# libraries ? Thanks.
5 Answers 5
You should pass in either:
- A byte array containing the chunk of data to compute the hash from
- A stream that restricts access to the chunk you want to computer the hash from
The second option isn’t all that hard, here’s a quick LINQPad program I threw together. Note that it lacks quite a bit of error handling, such as checking that the chunk is actually available (ie. that you’re passing in a position and length of the stream that actually exists and doesn’t fall off the end of the underlying stream).
Needless to say, if this should end up as production code I would add a lot of error handling, and write a bunch of unit-tests to ensure all edge-cases are handled correctly.
You would construct the PartialStream instance for your file like this:
Get File hashes using Windows PowerShell
Getting file hashes can be quite useful. This can be used for instance to make sure that backed up files are not corrupt or modified (by generating hashes before and after the process), or to make sure that no one tampered with an important file.
You may see it on download sites as well, but the use there is limited. The reason is simple: if an attacker managed to change the download file, there is a chance that the website was compromised as well. This could theoretically at least mean that the file hash displayed on the site was modified as well to fit the new malicious version of the download.
We have reviewed a considerable number of hashing related programs in the past: from the Windows shell extension HashTab, over Nirsoft’s HashMyFiles to File Check MD5 and MD5 Check Utility.
Get File hashes using Windows PowerShell
If you need to generate the hash of a file quickly on a Windows machine, then you may also use PowerShell for that.
It may not be as comfortable as some of the hashing programs out there, but it is a native implementation that does not require third-party software to work. Useful in restricted environments for instance, or when there is no Internet connection available to download these programs.
Hash generating was integrated into PowerShell 4.0. It is included in Windows 8.1 and Windows Server 2012 R2, and also available for Windows 7 Service Pack 1, Windows Server 2012, and Windows Server 2008 R2 Service Pack 1.
- Tap on the Windows-key, type PowerShell, and hit the Enter-key to start it up.
The main command is get-filehash FILEPATH, e.g. get-filehash c:\test.txt.
Get-FileHash uses the Sha256 algorithm by default. You may specify a different algorithm instead using the -Algorithm parameter.
Supported are: SHA1, SHA256, SHA384, SHA512, MACTripleDES, MD5, RIPEMD160
Note that MD5 and SHA1 are not considered secure anymore but are still supported.
So, to generate a Sha512 hash you would use the command get-filehash -Algorithm Sha512 c:\test.txt.
You may also use -LiteralPath or -InputStream instead of the default path option.
- LiteralPath: get-filehash -LiteralPath -Algorithm SHA512 c:\test.txt.
- InputStream get-filehash -InputStream -Algorithm SHA512 Stream.
The core difference between path and literalpath is that literalpath supports no wildcards, and is used exactly as it is typed.
CertUtil
CertUtil is another native Windows program that you may use to compute hashes of files. You can run the program from the command prompt, or using PowerShell.
The base command is certutil -hashfile PATH, e.g. certutil -hashfile c:\example.txt.
You may specify the hash algorithm as well. Supported are MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512. The default algorithm is MD5.
To use a different hash algorithm, specify it after the command, e.g. certutil -hashfile c:\example.txt SHA512.
Closing Words
You may use the commands in scripts to compute hashes for several files in one operation. The two native tools get-filehash and certutil are quite handy for the quick computation of hashes on Windows, and also for script use. (via Genbeta (Spanish))