public static string GetMD5(string myString) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString); byte[] targetData = md5.ComputeHash(fromData); string byte2String = null; for (int i = 0; i < targetData.Length; i++) { byte2String += targetData[i].ToString("X2"); } return byte2String; }
#region MD5加密 /// <summary> /// MD5获取 /// </summary> /// <returns>字符串</returns> public static string GetMd5(string str) { MD5 md = MD5.Create(); byte[] buffer = Encoding.UTF8.GetBytes(str); byte[] bf = md.ComputeHash(buffer); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bf.Length; i++) { sb.Append(bf[i].ToString("x2")); } return sb.ToString(); } #endregion