其实在.net 有一个最简单实现MD5的方法
<summary>
/// MD5加密
/// </summary>
/// <param name="toCryString">被加密字符串</param>
/// <returns>加密后的字符串</returns>
public static string MD5(string toCryString)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(toCryString, "MD5");
}
方法2:
public static string MD5(string str)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(str));
string str2 = "";
for(int i=0;i<result.Length;i++)
{
str2 += string.Format("{0:x}",result[i]);
}
return str2;
}