2012-02-12 10:46:16|?次阅读|上传:wustguangh【已有?条评论】发表评论
4、MD5不可逆加密
4.1、32位加密
/// <summary> /// 与ASP兼容的MD5加密算法 /// </summary> public string GetMD5(string s, string _input_charset) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] t = md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(s)); StringBuilder sb = new StringBuilder(32); for (int i = 0; i < t.Length; i++) sb.Append(t[i].ToString("x").PadLeft(2, '0')); return sb.ToString(); }
4.2、16位加密
public static string GetMd5Str(string ConvertString) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); string t2 =BitConverter.ToString( md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)) , 4 , 8); t2 = t2.Replace("-", ""); return t2; }