c#sha1加密
一,参考文献:
加密参考自: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);
//把比特流连接起来,附加到字符串里面。
//比特流转化字符串万能linq:.Aggregate("", (s, e) => s + String.Format("{0:x2}", e), s => s)
string hashValue = hmac.ComputeHash(byte2).Aggregate("", (s, e) => s + String.Format("{0:x2}", e), s => s);
return hashValue;
}
浙公网安备 33010602011771号