首页 > 编程语言 > 详细

C# SHA256加密算法记录

时间:2016-02-17 11:02:31      阅读:661      评论:0      收藏:0      [点我收藏+]
 1 using System.Text;
 2 using System.Diagnostics;
 3 using System.Security;
 4 using System.Security.Cryptography;
 5 
 6 protected void Page_Load(object sender, EventArgs e)
 7     {
 8         string salted = "abcdefghijklm";
 9         string digest = SHA256Encrypt(salted);
10 
11         byte[] b = System.Text.Encoding.Default.GetBytes(digest);
12 
13         Response.Write(Convert.ToBase64String(b));
14         Response.End();
15     }
16 
17     public string SHA256Encrypt(string strIN)
18     {
19         //string strIN = getstrIN(strIN);
20         byte[] tmpByte;
21         SHA256 sha256 = new SHA256Managed();
22 
23         tmpByte = sha256.ComputeHash(GetKeyByteArray(strIN));
24         sha256.Clear();
25 
26         return GetStringValue(tmpByte);
27 
28     }
29 
30     private string GetStringValue(byte[] Byte)
31     {
32         string tmpString = "";
33         ASCIIEncoding Asc = new ASCIIEncoding();
34         tmpString = Asc.GetString(Byte);
35         return tmpString;
36     }
37 
38     private byte[] GetKeyByteArray(string strKey)
39     {
40         ASCIIEncoding Asc = new ASCIIEncoding();
41 
42         int tmpStrLen = strKey.Length;
43         byte[] tmpByte = new byte[tmpStrLen - 1];
44 
45         tmpByte = Asc.GetBytes(strKey);
46 
47         return tmpByte;
48 
49     }

 

C# SHA256加密算法记录

原文:http://www.cnblogs.com/cookiebin/p/SHA256.html

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