码迷,mamicode.com
首页 > 其他好文 > 详细

md5盐值加密

时间:2018-10-23 10:58:22      阅读:762      评论:0      收藏:0      [点我收藏+]

标签:vat   实例   using   ==   coding   param   默认   utf8   encoding   

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盐值加密

标签:vat   实例   using   ==   coding   param   默认   utf8   encoding   

原文地址:https://www.cnblogs.com/LiChen19951127/p/9834874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!