public static String GetMD5(String sDataIn)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
Byte[] bytValue, bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
String sTemp = "";
for (int i = 0; i < bytHash.Length; i++)
{
sTemp += bytHash[i].ToString("X").PadLeft(2, '0');
}
return sTemp.ToLower();
}
在程序中調用:
String s = GetMD5("123456");
MessageBox.Show(s);
獲取MD5值:
Response.Write(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5"));