This MD5 encryption, decryption method will be used.
Code memo when using:Response.Write (FormsAuthentication.HashPasswordForStoringInConfigFile ("The string to encrypt","MD5"));
The following is the encrypted, decrypted code section:
/*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)); } */usingSystem;usingSystem.IO;usingSystem.Text;usingSystem.Security.Cryptography;usingsystem.web;namespaceyd.common{/// <summary> ///Add password class/// </summary> Public classCencrypt {/// <summary> ///Encrypt/// </summary> /// <param name= "inputstring" ></param> /// <returns></returns> Public Static stringDesencrypt (stringinputstring) { returndesencrypt (inputstring, Key); } /// <summary> ///decryption/// </summary> /// <param name= "inputstring" ></param> /// <returns></returns> Public Static stringDesdecrypt (stringinputstring) { returnDesdecrypt (inputstring, Key); } /// <summary> ///secret key/// </summary> Private Static stringKey {Get { return "Hongye10"; } } /// <summary> ///Encrypt string///Note: The key must be 8-bit/// </summary> /// <param name= "StrText" >string</param> /// <param name= "Encryptkey" >secret key</param> /// <param name= "Encryptkey" >returns the encrypted string</param> Public Static stringDesencrypt (stringInputString,stringEncryptkey) { 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=NewDESCryptoServiceProvider (); byte[] Inputbytearray =Encoding.UTF8.GetBytes (inputstring); MemoryStream Ms=NewMemoryStream (); CryptoStream CS=NewCryptoStream (MS, Des. CreateEncryptor (Bykey, IV), cryptostreammode.write); Cs. Write (Inputbytearray,0, inputbytearray.length); Cs. FlushFinalBlock (); returnconvert.tobase64string (Ms. ToArray ()); } Catch(System.Exception error) {//return error. Message; return NULL; } } /// <summary> ///decrypting a string/// </summary> /// <param name= "this.inputstring" >a dense string</param> /// <param name= "Decryptkey" >secret key</param> /// <param name= "Decryptkey" >returns the decrypted string</param> Public Static stringDesdecrypt (stringInputString,stringDecryptkey) { byte[] Bykey =NULL; byte[] IV = {0x12,0x34,0x56,0x78,0x90,0xAB,0xCD,0xEF }; byte[] Inputbytearray =NewByte[inputstring.length]; Try{Bykey= System.Text.Encoding.UTF8.GetBytes (Decryptkey.substring (0,8)); DESCryptoServiceProvider des=NewDESCryptoServiceProvider (); Inputbytearray=convert.frombase64string (inputstring); MemoryStream Ms=NewMemoryStream (); CryptoStream CS=NewCryptoStream (MS, Des. CreateDecryptor (Bykey, IV), cryptostreammode.write); Cs. Write (Inputbytearray,0, inputbytearray.length); Cs. FlushFinalBlock (); System.Text.Encoding Encoding=NewSystem.Text.UTF8Encoding (); returnencoding. GetString (Ms. ToArray ()); } Catch(System.Exception error) {//return error. Message; return NULL; } } }}
Implementation of MD5 encryption and decryption methods in ASP.