代码如下 public string md5(string str, int code) //code 16 或 32
{
if (code == 16) //16位MD5加密(取32位加密的9~25字符)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
} if (code == 32) //32位加密
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str.Trim(), "MD5").ToString();
} return "00000000000000000000000000000000";
}
}
我选择的是32位的加密为什么出来后是16位的啊?
{
if (code == 16) //16位MD5加密(取32位加密的9~25字符)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
} if (code == 32) //32位加密
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str.Trim(), "MD5").ToString();
} return "00000000000000000000000000000000";
}
}
我选择的是32位的加密为什么出来后是16位的啊?
试下这个:
string qswhMD5(string str){
/************qiushuiwuhen(2002-9-27)***************/
byte[] b=System.Text.Encoding.Default.GetBytes(str);
b=new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(b);
string ret="";
for(int i=0;i<b.Length;i++)
ret+=b[i].ToString("x").PadLeft(2,'0');
return ret;
}
using System.Web.Security;namespace Usb_Server
{
public class ToMd5
{
/// <summary>
/// 给密码加密
/// </summary>
/// <param name="str"></param>
/// <param name="code"></param>
/// <returns></returns>
public string md5(string str, int code)
{
if (code == 16) //16位MD5加密(取32位加密的9~25字符)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
} if (code == 32) //32位MD5加密
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
} return "";
} }
}