/// <summary> /// MD5加密 /// </summary> /// <param name="input">需要加密的字符串</param> /// <returns></returns> public static string MD5Encrypt(string input) { return MD5Encrypt(input, new UTF8Encoding()); } /// <summary> /// md5加密16|32位 /// </summary> /// <param name="input"></param> /// <param name="length"></param> /// <returns></returns> public static string MD5Encrypt(string input, int length) { string res = MD5Encrypt(input, new UTF8Encoding()); if (length == 16) { res = res.Substring(8, 16); } return res; } /// <summary> /// MD5加密 /// </summary> /// <param name="input">需要加密的字符串</param> /// <param name="encode">字符的编码</param> /// <returns></returns> public static string MD5Encrypt(string input, Encoding encode) { if (string.IsNullOrEmpty(input)) { return null; } MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] data = md5Hasher.ComputeHash(encode.GetBytes(input)); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("x2")); } return sBuilder.ToString(); }
如果本文对你有所帮助,请打赏——1元就足够感动我:)
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
关注公众号:
作者: 王磊
出处: http://vipstone.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,请标明出处。