MD5(加密)
使用MD5加密:
MD5(12位)
password为需要加密的
public string MD512(string password) { var md5 = new MD5CryptoServiceProvider(); string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8); t2 = t2.Replace("-", ""); return t2; }
MD5(32位)
public string MD532(string password) { MD5 md5 = MD5.Create();//实例化一个md5对象 //加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password)); //通过循环,将字节类型转化为字符串,此字符串是常规字符格式化所得 string str = ""; for (int i = 0; i < s.Length; i++) { //将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母, //如果使用大写(X)则格式后的字符是大写字符 str += s[i].ToString("x"); } return str; }
MD5(64位)
public string MD564(string password) { MD5 md5 = MD5.Create(); byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password)); return Convert.ToBase64String(s); }