标签:
#region Hash算法
/// <summary>
/// Hash算法
/// </summary>
/// <param name="myStr"></param>
/// <returns></returns>
public static string Hash(string myStr)
{
//建立SHA1对象
SHA1 sha = new SHA1CryptoServiceProvider();
//将mystr转换成byte[]
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] dataToHash = enc.GetBytes(myStr);
//Hash运算
byte[] dataHashed = sha.ComputeHash(dataToHash);
//将运算结果转换成string
string hash = BitConverter.ToString(dataHashed).Replace("-", "");
return hash;
}
#endregion
标签:
原文地址:http://www.cnblogs.com/a-mumu/p/4335083.html