復制代碼 代碼如下:
Response.Write(FormsAuthentication.HashPasswordForStoringInConfigFile("www.mzwu.com", "MD5"));
//結果:D66E1F138689B9B5AA4C520D9EAFFB61
復制代碼 代碼如下:
Response.Write(MD5("www.mzwu.com",32))
'結果:d66e1f138689b9b5aa4c520d9eaffb61
復制代碼 代碼如下:
Response.Write(FormsAuthentication.HashPasswordForStoringInConfigFile("木子屋", "MD5"));
//結果:34D9CBD5164C47058DFA3AF832E2D1DC
復制代碼 代碼如下:
Response.Write(MD5("木子屋",32))
'結果:0a40a90190da023ae7aa17771663a41e
復制代碼 代碼如下:
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
Response.Write(BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding("gb2312").GetBytes("木子屋"))).Replace("-", ""));
//結果:0A40A90190DA023AE7AA17771663A41E
復制代碼 代碼如下:
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
Response.Write(BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding("utf-8").GetBytes("木子屋"))).Replace("-", ""));
//結果:34D9CBD5164C47058DFA3AF832E2D1DC
復制代碼 代碼如下:
/**//// <summary>
/// 對字符串進行MD5加密
/// </summary>
/// <param>要加密的字符串</param>
/// <param>字符串編碼格式</param>
/// <example>str = MD5("木子屋","gb2312");</example>
/// <returns></returns>
public string MD5(string text, string charset)
{
return (MD5(text, charset, false));
}
/**//// <summary>
/// 對字符串或參數值進行MD5加密
/// </summary>
/// <param>要加密的字符串或參數名稱</param>
/// <param>字符串編碼格式</param>
/// <param>加密字符串類型 true:參數值 false:字符串</param>
/// <returns></returns>
public string MD5(string text, string charset, bool isArg)
{
try
{
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
if (isArg)
{
NameValueCollection Collect = HttpUtility.ParseQueryString(Request.Url.Query, Encoding.GetEncoding(charset));//使用Collect接收參數值
if (Collect[text] != null)
{
return BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(Collect[text].ToString()))).Replace("-", "");
}
}
else
{
return BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(text))).Replace("-", "");
}
}
catch { }
return string.Empty;
}
復制代碼 代碼如下:
using System.Text;
using System.Web.Security;
using System.Security.Cryptography;
using System.Collections.Specialized;
新聞熱點
疑難解答
圖片精選