码迷,mamicode.com
首页 > 编程语言 > 详细

C# SHA256加密算法记录

时间:2016-02-17 11:03:21      阅读:248      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!