MD5加密

作者:追风剑情 发布于:2015-12-3 15:10 分类:C#

需导入 using System.Security.Cryptography;

public static class MD5Crypto
{
	//MD5加密(生成32位字符码)
	public static string Encrypt(string input)
	{
		//注意: 编码不同,生成的MD5值也不同
		byte[] buffer = Encoding.UTF8.GetBytes(input);
		MD5 md5 = new MD5CryptoServiceProvider();
		byte[] res = md5.ComputeHash(buffer);
		return BitConverter.ToString(res).Replace("-", "");
	}

	//密码混淆字符串
	public const string PASSWORD_PREFIX = "QwErT#2020&$kLjKNM986sljk@";
	public const string PASSWORD_POSTFIX = "Iklsn%$#@LIl.rXVPo^#123@";
	public static string EncryptPassword(string password)
	{
		string mix_password = string.Format("{0}{1}{2}", PASSWORD_PREFIX, password, PASSWORD_POSTFIX);
		return Encrypt(mix_password);
	}
}

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号