Implementation of MD5 encryption and decryption methods in ASP.

Source: Internet
Author: User
Tags md5 encryption

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.