// Dedicated for URL parameter encryption # region ========= encryption ======= private static Byte [] key; private static Byte [] IV = new Byte [] {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; /// <summary> /// encryption /// </summary> /// <param name = "Text"> </param> /// <returns> </ returns> public static string UrlEncrypt (string strToEncrypt) {return UrlEncrypt (strToEncrypt ,"#! 12 ^ 0 #@");} /// <summary> /// encryption /// </summary> /// <param name = "strToEncrypt"> string to be encrypted </param> /// <param name = "strEncryptKey"> key </param> // <returns> encrypted string </returns> public static string UrlEncrypt (string strToEncrypt, string strEncryptKey) {if (! String. isNullOrEmpty (strToEncrypt) {try {key = Encoding. UTF8.GetBytes (strEncryptKey. substring (0, 8); Byte [] inputByteArray = Encoding. UTF8.GetBytes (strToEncrypt); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); MemoryStream MS = new MemoryStream (); CryptoStream cs = new CryptoStream (MS, des. createEncryptor (key, IV), CryptoStreamMode. write); cs. write (inputByteArray, 0, inputByteAr Ray. length); cs. flushFinalBlock (); return Convert. toBase64String (ms. toArray ();} catch (Exception ex) {// return ex. message; return null ;}} else {return null ;}} # endregion # region ========= decryption ======== public static string UrlDecrypt (string strToDecrypt) {return UrlDecrypt (strToDecrypt ,"#! 12 ^ 0 #@");} /// <summary> /// decrypt /// </summary> /// <param name = "strToDecrypt"> string to be decrypted </param> /// <param name = "strEncryptKey"> key, must be the same as the Encrypted Key </param> // <returns> decrypted string </returns> public static string UrlDecrypt (string strToDecrypt, string strEncryptKey) {if (! String. isNullOrEmpty (strToDecrypt) {strToDecrypt = strToDecrypt. replace ("", "+"); // if this part of the code is removed, the aforementioned situation will occur, and the error or decrypted data will become null. Try {key = Encoding. UTF8.GetBytes (strEncryptKey. substring (0, 8); Byte [] inputByteArray = Convert. fromBase64String (strToDecrypt); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); MemoryStream MS = new MemoryStream (); CryptoStream cs = new CryptoStream (MS, des. createDecryptor (key, IV), CryptoStreamMode. write); cs. write (inputByteArray, 0, inputByteArray. length); cs. flushFinalBlock (); return Encoding. UTF8.GetString (ms. toArray ();} catch (Exception ex) {// return ex. message; return null ;}} else {return null ;}# endregion