Skip to content

Instantly share code, notes, and snippets.

@mafis
Created September 20, 2010 08:27
Show Gist options
  • Save mafis/587595 to your computer and use it in GitHub Desktop.
Save mafis/587595 to your computer and use it in GitHub Desktop.
protected string GetMD5HashFromFile(string fileName)
{
if (!File.Exists(fileName))
return String.Empty;
FileStream file = new FileStream(fileName, FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment