c# 生成SHA1加密字符串

 从网上找到的一种加密代码:

var enstr ="abcdefg";
var strRes = Encoding.Default.GetBytes(enstr);
HashAlgorithm iSha = new SHA1CryptoServiceProvider();
strRes = iSha.ComputeHash(strRes);
var enText = new StringBuilder();
foreach (byte iByte in strRes)
{
    enText.AppendFormat("{0:x2}", iByte);
}    
 

  

还有另一种SHA1加密,我用来做腾讯云签名:

HMACSHA1 hmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(SecretKey));
byte[] rstRes = hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(str));
string strs =  Convert.ToBase64String(rstRes);
return System.Web.HttpUtility.UrlEncode(strs);

 

posted @ 2016-07-26 15:24  大稳·杨  阅读(15852)  评论(0编辑  收藏  举报