Password encryption method

Source: Internet
Author: User

The source code to encrypt the password

Users. PASSWD = Decryption.encryptdes (getmd5str (_httpreuqeststring["Passwd"]. ToString ()), Commonhelper.getappsettings ("pagepwd"));
    /// <summary>    ///MD5 16-bit encryption password is lowercase/// </summary>    /// <param name= "convertstring" ></param>    /// <returns></returns>     Public Static stringGETMD5STR (stringconvertstring) {System.Security.Cryptography.MD5CryptoServiceProvider MD5=NewSystem.Security.Cryptography.MD5CryptoServiceProvider (); stringT2 = bitconverter.tostring (Md5.computehash (UTF8Encoding.Default.GetBytes (convertstring)),4,8); T2= T2. Replace ("-",""); T2=T2.        ToLower (); returnT2; }

Des encryption and decryption method

//default key Vector        Private Static byte[] Keys = {0xEF,0xAB,0x56,0x78,0x90,0x34,0xCD,0x12 }; /// <summary>        ///des encrypted String/// </summary>        /// <param name= "encryptstring" >string to encrypt</param>        /// <param name= "Encryptkey" >encryption key, required for 8-bit</param>        /// <returns>encryption successfully returns the encrypted string, failed to return the source string</returns>         Public Static stringEncryptdes (stringEncryptString,stringEncryptkey) {            Try            {                byte[] RgbKey = Encoding.UTF8.GetBytes (encryptkey.substring (0,8)); byte[] Rgbiv =Keys; byte[] Inputbytearray =Encoding.UTF8.GetBytes (encryptstring); DESCryptoServiceProvider DCSP=NewDESCryptoServiceProvider (); MemoryStream Mstream=NewMemoryStream (); CryptoStream Cstream=NewCryptoStream (Mstream, Dcsp.createencryptor (RgbKey, Rgbiv), cryptostreammode.write); Cstream.write (Inputbytearray,0, inputbytearray.length);                Cstream.flushfinalblock (); returnconvert.tobase64string (Mstream.toarray ()); }            Catch            {                returnencryptstring; }        }        /// <summary>        ///des decryption String/// </summary>        /// <param name= "decryptstring" >string to decrypt</param>        /// <param name= "Decryptkey" >Decryption key, required to be 8-bit, same as encryption key</param>        /// <returns>decryption succeeded in returning the decrypted string, failed to return the source string</returns>         Public Static stringDecryptdes (stringDecryptstring,stringDecryptkey) {            Try            {                byte[] RgbKey = Encoding.UTF8.GetBytes (decryptkey.substring (0,8)); byte[] Rgbiv =Keys; byte[] Inputbytearray =convert.frombase64string (decryptstring); DESCryptoServiceProvider DCSP=NewDESCryptoServiceProvider (); MemoryStream Mstream=NewMemoryStream (); CryptoStream Cstream=NewCryptoStream (Mstream, DCSP.                CreateDecryptor (RgbKey, Rgbiv), cryptostreammode.write); Cstream.write (Inputbytearray,0, inputbytearray.length);                Cstream.flushfinalblock (); returnEncoding.UTF8.GetString (Mstream.toarray ()); }            Catch            {                returndecryptstring; }        }

Password encryption method

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.