Skip to content

Instantly share code, notes, and snippets.

@pilotgeraldb
Last active June 6, 2016 20:22
Show Gist options
  • Save pilotgeraldb/db3626db98c49cd8e43bce863690fff1 to your computer and use it in GitHub Desktop.
Save pilotgeraldb/db3626db98c49cd8e43bce863690fff1 to your computer and use it in GitHub Desktop.
creates a hash of a file from a filename
using (MD5 md5 = MD5.Create())
{
using (FileStream stream = File.OpenRead(filename))
{
byte[] bytes = md5.ComputeHash(stream);
bool uppercase = false;
StringBuilder result = new StringBuilder(bytes.Length * 2);
for (int i = 0; i < bytes.Length; i++)
{
result.Append(bytes[i].ToString(uppercase ? "X2" : "x2"));
}
return result.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment