md5盐值加密
Posted lichen19951127
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了md5盐值加密相关的知识,希望对你有一定的参考价值。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace sci_project
{
public static class PasswordHelper
{
/// <summary>
/// MD5 加密字符串
/// </summary>
/// <param name="rawPass">源字符串</param>
/// <returns>加密后字符串</returns>
private static string MD5Encoding(string rawPass)
{
// 创建MD5类的默认实例:MD5CryptoServiceProvider
MD5 md5 = MD5.Create();
byte[] bs = Encoding.UTF8.GetBytes(rawPass);
byte[] hs = md5.ComputeHash(bs);
StringBuilder sb = new StringBuilder();
foreach (byte b in hs)
{
// 以十六进制格式格式化
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
/// <summary>
/// MD5盐值加密
/// </summary>
/// <param name="rawPass">源字符串</param>
/// <param name="salt">盐值</param>
/// <returns>加密后字符串</returns>
public static string MD5Encoding(string rawPass, object salt)
{
if (salt == null) return rawPass;
return MD5Encoding(rawPass + "{" + salt.ToString() + "}");
}
}
}
以上是关于md5盐值加密的主要内容,如果未能解决你的问题,请参考以下文章