1 usingSystem.Text;2 usingSystem.Diagnostics;3 usingsystem.security;4 usingSystem.Security.Cryptography;5 6 protected voidPage_Load (Objectsender, EventArgs e)7 {8 stringSalted ="ABCDEFGHIJKLM";9 stringDigest =sha256encrypt (salted);Ten One byte[] B =System.Text.Encoding.Default.GetBytes (digest); A - Response.Write (convert.tobase64string (b)); - Response.End (); the } - - Public stringSha256encrypt (stringStrin) - { + //string strin = Getstrin (Strin); - byte[] tmpbyte; +SHA256 sha256 =Newsha256managed (); A atTmpbyte =Sha256.computehash (Getkeybytearray (Strin)); - sha256. Clear (); - - returnGetStringValue (tmpbyte); - - } in - Private stringGetStringValue (byte[] Byte) to { + stringTmpstring =""; -ASCIIEncoding ASC =Newasciiencoding (); theTmpstring =asc.getstring (Byte); * returntmpstring; $ }Panax Notoginseng - Private byte[] Getkeybytearray (stringstrkey) the { +ASCIIEncoding ASC =Newasciiencoding (); A the intTmpstrlen =strkey.length; + byte[] Tmpbyte =New byte[Tmpstrlen-1]; - $Tmpbyte =asc.getbytes (strkey); $ - returnTmpbyte; - the}
C # SHA256 encryption algorithm record