/* Usage protected void Page_Load (object sender, EventArgs e) {//encrypt this. Title = Cencrypt.desencrypt ("pwd", Cencrypt.key); This. Title + = Cencrypt.desdecrypt (this. Title, Cencrypt.key); Response.Write (Cencrypt.desdecrypt ("gayyhdlqunc=", Cencrypt.key)); } */using system;using system.io;using system.text;using system.security.cryptography;using System.Web;namespace YD. common{//<summary>//Plus password class///</summary> public class Cencrypt {//<summary> ; Encrypt//</summary>//<param name= "inputstring" ></param>//<returns>< ;/returns> public static string Desencrypt (string inputstring) {return desencrypt (inputstring , Key); }//<summary>//Decrypt//</summary>//<param name= "InputString" ></par am>//<returns></returns> public static string Desdecrypt (sTring inputstring) {return desdecrypt (inputstring, Key); }///<summary>//key//</summary> private static string key { get {return "Hongye10"; }}///<summary>///encryption string///NOTE: Key must be 8 bit///</summary>//<PA Ram Name= "StrText" > String </param>//<param name= "Encryptkey" > Key </param>//<param NA Me= "Encryptkey" > returns the encrypted string </param> public static Strings Desencrypt (string inputstring, String encryptkey) {byte[] Bykey = null; Byte[] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; try {bykey = System.Text.Encoding.UTF8.GetBytes (encryptkey.substring (0, 8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); byte[] Inputbytearray = Encoding.UTF8.GetBYtes (inputstring); MemoryStream ms = new MemoryStream (); CryptoStream cs = new CryptoStream (MS, Des. CreateEncryptor (Bykey, IV), cryptostreammode.write); Cs. Write (Inputbytearray, 0, inputbytearray.length); Cs. FlushFinalBlock (); Return convert.tobase64string (Ms. ToArray ()); } catch (System.Exception error) {//return error. Message; return null; }}///<summary>//Decrypt string///</summary>//<param name= "this.inputst Ring > Secret string </param>//<param name= "Decryptkey" > Key </param>///<param name= "decry Ptkey "> returns decrypted string </param> public static Desdecrypt string (string inputstring, String decryptkey) { byte[] Bykey = null; Byte[] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; byte[] Inputbytearray =New Byte[inputstring.length]; try {bykey = System.Text.Encoding.UTF8.GetBytes (decryptkey.substring (0, 8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); Inputbytearray = convert.frombase64string (inputstring); MemoryStream ms = new MemoryStream (); CryptoStream cs = new CryptoStream (MS, Des. CreateDecryptor (Bykey, IV), cryptostreammode.write); Cs. Write (Inputbytearray, 0, inputbytearray.length); Cs. FlushFinalBlock (); System.Text.Encoding Encoding = new System.Text.UTF8Encoding (); return encoding. GetString (Ms. ToArray ()); } catch (System.Exception error) {//return error. Message; return null; } } }}
Encrypt decrypt (process password)