标签:style class blog code java http
1 【1】 计算文件MD5值的方法: 2 /// <summary> 3 /// 计算文件MD5值 4 /// </summary> 5 /// <param name="str">需要计算的文件路径</param> 6 /// <returns>MD5值</returns> 7 public static string MD5Value(String filepath) 8 { 9 MD5 md5 = new MD5CryptoServiceProvider(); 10 byte[] md5ch; 11 using (FileStream fs = File.OpenRead(filepath)) 12 { 13 md5ch = md5.ComputeHash(fs); 14 } 15 md5.Clear(); 16 string strMd5 = ""; 17 for (int i = 0; i < md5ch.Length - 1; i++) 18 { 19 strMd5 += md5ch[i].ToString("x").PadLeft(2, ‘0‘); 20 } 21 return strMd5; 22 }
1 //计算字符串的MD5 2 public static string GetMD5(string sDataIn) 3 { 4 MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); 5 byte[] bytValue, bytHash; 6 bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn); 7 bytHash = md5.ComputeHash(bytValue); 8 md5.Clear(); 9 string sTemp = ""; 10 for (int i = 0; i < bytHash.Length; i++) 11 { 12 sTemp += bytHash[i].ToString("X").PadLeft(2, ‘0‘); 13 } 14 return sTemp.ToLower(); 15 }
标签:style class blog code java http
原文地址:http://www.cnblogs.com/skyl/p/3781674.html