首页 > 代码库 > ASP.NET-SHA256加密方法

ASP.NET-SHA256加密方法

/// <summary>
/// SHA256加密
/// </summary>
/// <param name="strData"></param>
/// <returns></returns>
public static string GetSHA256HashFromString(string strData)
{
byte[] bytValue = http://www.mamicode.com/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();
}

ASP.NET-SHA256加密方法