string filePath = "c:\a.jpg"; using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); md5.ComputeHash(fs); fs.Close(); byte[] b = md5.Hash; string md5Value = BitConverter.ToString(b).Replace("-", string.Empty); }
其中md5Value即为计算后的值。