最简单的MD5算法
public string md5(string str, int code)
{
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, "MD5").ToLower();
}
return "00000000000000000000000000000000";
}
#endregion
//加密
public static string EnCode(string s)
{
string encodestr = "";
byte[] bytes = System.Text.Encoding.GetEncoding(0).GetBytes(s);
try
{
encodestr = Convert.ToBase64String(bytes);
}
catch
{
encodestr = s;
}
return encodestr;
}
//解密
public static string DeCode(string s)
{
string decodestr = "";
byte[] bytes = Convert.FromBase64String(s);
try
{
decodestr = System.Text.Encoding.GetEncoding(0).GetString(bytes);
}
catch
{
decodestr = s;
}
return decodestr;
}