你的位置:首页 > ASP.net教程

[ASP.net教程]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);