C# MD5加密的几种方法
管理提醒:
本帖被 gaolei2016 执行加亮操作(2010-01-21)
MD5加密是在网站开发经常使用到的加密方案。
在这里介绍几种MD5的几种方法。
1、中,MS有一套专用的加密使用方法:
/// code 为加密位数,16和32
public static string Md5(string str, int code)
{
//str = (str);
if (code == 16) //16位MD5加密(取32位加密的9~25字符)
{
return (str, "MD5").ToLower().Substring(8, 16);
}
else//32位加密
{
return (str, "MD5").ToLower();
}
2、MSDN 的案例:
/**/
/// <summary>
/// MD5加密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Md5(string str)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = ();
// Convert the input string to a byte array pute the hash.
byte[]data=puteHash(("UTF-8").GetBytes(str));
// return (data);//可以直接使用这个方法
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < ; i++)
{
(("x2"));
}
// Return the hexadecimal string.
return ();
}
}
3、在使用淘宝API时,淘宝提供的一个方法
/// <summary>
/// MD5加密并输出十六进制字符串
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Md5Hex(string str)
C# MD5加密方法 来自淘豆网www.taodocs.com转载请标明出处.