MD5加密
方法一:(32位)
/// <summary>
/// 重置密码
/// </summary>
/// <param name="pwd"></param>
/// <returns></returns>
public ActionResult CZ(string pwd)
{
//将字符串解析成字节数组 using System.Text;
byte[] buffer = Encoding.Default.GetBytes(pwd);
//使用MD5这个抽象类的Creat()方法创建一个虚拟的MD5类的对象
MD5 md5 =MD5.Create();//using System.Security.Cryptography;
//使用MD5实例的ComputeHash()方法处理字节数组
byte[] bufferNew = md5.ComputeHash(buffer);
string strNew = null;
for (int i = 0; i < bufferNew.Length; i++)
{
//对bufferNew字节数组中的每个元素进行十六机制转换人后拼接成strNew字符串
strNew += bufferNew[i].ToString("x2");
}
return Content("<script>alert('"+ strNew + "');location.href='/Users/Index';</script>");
}
方法二:(16位)
//using System.Security.Cryptography;
var md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(textBox2.Text)));
t2 = t2.Replace("-", "");