The following is the PHP code
<preclass=php name= "Code" > </pre><preclass=php name= "code" >php plus decryption function: </pre><preclass=php name= "Code" > </pre><preclass=php name= "Code" >functionEncrypt$string) { //Key file for encryption $key= "XXXXXXXX"; //Encryption Method $cipher _alg=Mcrypt_tripledes; //initializing vectors to increase security $iv= Mcrypt_create_iv (Mcrypt_get_iv_size ($cipher _alg, MCRYPT_MODE_ECB),Mcrypt_rand); //Start Encryption $encrypted _string= Mcrypt_encrypt ($cipher _alg,$key,$string, MCRYPT_MODE_ECB,$iv); return Base64_encode($encrypted _string);//Convert to 16//Return $encrypted _string; } functionDecrypt$string) { $string=Base64_decode($string); //Key file for encryption $key= "XXXXXXXX"; //Encryption Method $cipher _alg=Mcrypt_tripledes; //initializing vectors to increase security $iv= Mcrypt_create_iv (Mcrypt_get_iv_size ($cipher _alg, MCRYPT_MODE_ECB),Mcrypt_rand); //Start Decryption $decrypted _string= Mcrypt_decrypt ($cipher _alg,$key,$string, MCRYPT_MODE_ECB,$iv); return Trim($decrypted _string); }</PRE>
The following is the. NET code
usingSystem;usingSystem.Security.Cryptography;usingSystem.Text;/**//// <SUMMARY>///a summary description of the crypto3des. /// </SUMMARY> Public classcrypto3des{ Publiccrypto3des () {// //TODO: Add constructor logic here// } PrivateSystem.Text.Encoding Encoding; /**//// <SUMMARY> ///get the secret key/// </SUMMARY> Public stringKey {Get { return "xxxxxxxx"; } } /**//// <SUMMARY> ///Gets or sets the encoding of the encryption decryption/// </SUMMARY> PublicSystem.Text.Encoding Encoding {Get { if(Encoding = =NULL) {Encoding=System.Text.Encoding.UTF8; } returnencoding; } Set{encoding=value; } } /**//// <SUMMARY> ///Encrypt/// </SUMMARY> /// <param name= "strstring" ></PARAM> /// <param name= "strkey" ></PARAM> /// <param name= "encoding" ></PARAM> /// <RETURNS></RETURNS> Public stringEncrypt3des (stringstrstring) {DESCryptoServiceProvider DES=NewDESCryptoServiceProvider (); Des. Key= Encoding.GetBytes ( This. Key); Des. Mode=CIPHERMODE.ECB; Des. Padding=Paddingmode.zeros; ICryptoTransform desencrypt=DES. CreateEncryptor (); byte[] Buffer =encoding. GetBytes (strstring); returnConvert.tobase64string (Desencrypt.transformfinalblock (Buffer,0, buffer.length)); } /**//// <SUMMARY> ///decryption/// </SUMMARY> /// <param name= "strstring" ></PARAM> /// <param name= "strkey" ></PARAM> /// <RETURNS></RETURNS> Public stringDecrypt3des (stringstrstring) {DESCryptoServiceProvider DES=NewDESCryptoServiceProvider (); Des. Key= Encoding.UTF8.GetBytes ( This. Key); Des. Mode=CIPHERMODE.ECB; Des. Padding=Paddingmode.zeros; ICryptoTransform Desdecrypt=DES. CreateDecryptor (); byte[] Buffer =convert.frombase64string (strstring); returnUTF8Encoding.UTF8.GetString (Desdecrypt.transformfinalblock (Buffer,0, buffer.length)); }}