首页 > 编程语言 > 详细

C# Hash算法

时间:2015-03-13 15:51:49      阅读:370      评论:0      收藏:0      [点我收藏+]

#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

C# Hash算法

原文:http://www.cnblogs.com/a-mumu/p/4335083.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!