标签:
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 }
标签:
原文地址:http://www.cnblogs.com/cookiebin/p/SHA256.html