ASP.NET-SHA256加密方法

/// <summary>
/// SHA256加密
/// </summary>
/// <param name="strData"></param>
/// <returns></returns>
public static string GetSHA256HashFromString(string strData)
{
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(strData);
SHA256 sha256 = new SHA256CryptoServiceProvider();

byte[] retVal = sha256.ComputeHash(bytValue);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}

posted @ 2017-07-17 14:30  举个栗子oO  阅读(2128)  评论(0编辑  收藏  举报