using System.Security.Cryptography;
using System.Text;
namespace learun.util
{
///
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.09.13
/// 描 述:md5加密
///
public class Md5Helper
{
#region "MD5加密"
///
/// MD5加密
///
/// 加密字符
/// 加密位数16/32
///
public static string Encrypt(string str, int code)
{
string strEncrypt = string.Empty;
if (code == 16)
{
strEncrypt = Hash(str).Substring(8, 16);
}
if (code == 32)
{
strEncrypt = Hash(str);
}
return strEncrypt;
}
///
/// 32位MD5加密(小写)
///
/// 输入字段
///
public static string Hash(string input)
{
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
#endregion "MD5加密"
}
}