首页 > 其他 > 详细

c#sha1加密

时间:2014-02-13 22:18:53      阅读:485      评论:0      收藏:0      [点我收藏+]

一,参考文献:

 加密参考自:http://msdn.microsoft.com/zh-cn/library/system.security.cryptography.hmacsha1(v=vs.110).aspx

 Aggregate参考自:http://msdn.microsoft.com/zh-cn/library/vstudio/system.linq.enumerable.aggregate(v=vs.110).aspx

二:步骤

需要引入2个命名空间:

using System.Security.Cryptography;
using System.Linq;//注意linq,是Aggregate必须的方法。这个是同事帮忙找到的。msdn没错,不过,这个方法放到了linq中。

//sha1加密(标准)
public string HMAC1(string publickey, string list1)
{
byte[] byte1 = System.Text.Encoding.UTF8.GetBytes(publickey);
byte[] byte2 = System.Text.Encoding.UTF8.GetBytes(list1);
HMACSHA1 hmac = new HMACSHA1(byte1);

//把比特流连接起来,附加到字符串里面
string hashValue = hmac.ComputeHash(byte2).Aggregate("", (s, e) => s + String.Format("{0:x2}", e), s => s);
return hashValue;
}

c#sha1加密

原文:http://www.cnblogs.com/defoliate/p/3548085.html

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