MSDN has a page on how to get the MD5 hash of a string.
Easy enough, but if you follow their example exactly for a file and use File.ReadAllText() to get the string, you will get the wrong MD5 string for binary files. Instead, use File.ReadAllBytes() to bypass encoding issues. (This also applies to SHA1 hashing.)
12 private static string GetMD5Hash(string filePath)
13 {
14 byte[] computedHash =
15 new MD5CryptoServiceProvider()
16 .ComputeHash(File.ReadAllBytes(filePath));
17
18 var sBuilder = new StringBuilder();
19 foreach (byte b in computedHash)
20 {
21 sBuilder.Append(b.ToString("x2").ToLower());
22 }
23 return sBuilder.ToString();
24 }