写法一
using System.Security.Cryptography; //安全.密码术 MD5...
using System.Text; //Encoding...
// TODO:
string password = "1234567890";
string resultSrt; //输出结果
MD5 md5 = MD5.Create(); //[1]实例化MD5对象 不能new
byte[] byteStr = md5.ComputeHash(Encoding.UTF8.GetBytes(password)); //[2]加密
resultSrt = BitConverter.ToString(byteStr); //[3]加密结果转换 显示/保存
// = E8-07-F1-FC-F8-2D-13-2F-9B-B0-18-CA-67-38-A1-9F
//BitConverter转换出来的字符之间都会有个-分隔
resultSrt = resultSrt.Replace("-", ""); //[4]去除符号-
// = E807F1FCF82D132F9BB018CA6738A19F
Response.Write(resultSrt + "<br>");
写法二
using System.Web.Security; //自带加密
// 一句话搞定
Response.Write(FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5") + "<br />");
// =E807F1FCF82D132F9BB018CA6738A19F