Skip to content

Instantly share code, notes, and snippets.

@kventil
Created May 26, 2015 08:04
Show Gist options
  • Save kventil/cdd1054f51465c3b52b6 to your computer and use it in GitHub Desktop.
Save kventil/cdd1054f51465c3b52b6 to your computer and use it in GitHub Desktop.
get md5-hash (Supports filesize > 2GB but is very slow!)
function md5hash($path)
{
$fullPath = Resolve-Path $path
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$file = [System.IO.File]::Open($fullPath,[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
[System.BitConverter]::ToString($md5.ComputeHash($file))
$file.Dispose()
}
md5hash($args[0])
@ccoenen
Copy link

ccoenen commented May 26, 2015

should be noted that you could also swap the service provider in line 4 to one of the following. The interface is the same, so it should work right away:

  • SHA1CryptoServiceProvider
  • SHA256CryptoServiceProvider
  • SHA384CryptoServiceProvider
  • SHA512CryptoServiceProvider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment