Tag Archives: Windows

2 ways to Generate an MD5 hash using Windows Built in tools

Powershell 4.0 and above include the Get-FileHash cmdlet which you can use to calculate the MD5 (among others) hash for a file.

If you don’t have Powershell 4.0, there are some other options to generate a hash.

Using the Certutil.exe command line tool

The Certutil.exe command line tool can be used to generate the MD5 hash of a file.

  1. Start an elevated command prompt
  2. Type the following command: certutil -hashfile [file] MD5
    Where [file] is the full path to the file.

certutil-md5

 

 

Using Powershell

If you don’t have powershell 4.0, you can use the following commands:

  1. $algo = [Security.Cryptography.HashAlgorithm]::Create(“MD5″)
  2. $str= ([System.IO.StreamReader]”C:\temp\test.file”).BaseStream
  3. $b = $algo.ComputeHash($str)
  4. -Join ($b | ForEach {“{0:x2}” -f $_})
  5. $str.Close()

powershell-md5

 

 

It would also be possible to use [System.IO.File]::ReadAlBytes and pass the output to the ComputeHash method, but ReadAllBytes will fail on files larger than 2GB.

When using a stream, you should be able to use files of all sizes.