Created
December 20, 2016 04:04
-
-
Save camark/6a59094ad594b204f241ae2e9193f7c1 to your computer and use it in GitHub Desktop.
计算文件MD5值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string GetMD5HashFromFile(string fileName) | |
{ | |
try | |
{ | |
FileStream file = new FileStream(fileName, FileMode.Open); | |
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.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(); | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception(“GetMD5HashFromFile() fail,error:” + ex.Message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment