1 /// <summary> 2 /// 计算文件的MD5值 3 /// </summary> 4 public static string md5file(string file) { 5 try { 6 FileStream fs = new FileStream(file, FileMode.Open); 7 System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); 8 byte[] retVal = md5.ComputeHash(fs); 9 fs.Close(); 10 11 StringBuilder sb = new StringBuilder(); 12 for (int i = 0; i < retVal.Length; i++) { 13 sb.Append(retVal[i].ToString("x2")); 14 } 15 return sb.ToString(); 16 } catch (Exception ex) { 17 throw new Exception("md5file() fail, error:" + ex.Message); 18 } 19 }
以上这个函数是在Unity项目中的SimpleFramework热更新框架摘出来的,希望在其他项目中不用再自己写了,特此标记。