I am also a novice php, through W3cschool to understand the basic principles of PHP after the write. But still rookie.
First, regardless of 3DES encryption method is right, methods are online, in the run time reported a mistake, the younger brother died. Find out and finally find out the way.
<?php/*** * PHP version 3DES plus decryption class * * Can be compatible with Java 3DES (desede) encryption * * @Author: Luo Hui (Farmer.luo at gmail.com) * * @version: V0.1 2008 .12.04**/class crypt3des{Public $key = "01234567890123456789012345678912";p ublic $iv = "23456789";//like java:private S Tatic byte[] Myiv = {50, 51, 52, 53, 54, 55, 56, 57};//Encrypt public Function encrypt ($input) {$input = $this->padding ($in Put), $key = Base64_decode ($this->key), $td = Mcrypt_module_open (Mcrypt_3des, ", MCRYPT_MODE_CBC,");//Use Mcrypt_ 3DES algorithm, CBC mode Mcrypt_generic_init ($TD, $key, $this->iv);//initial processing $data = Mcrypt_generic ($TD, $input);//Encryption Mcrypt_ Generic_deinit ($TD);//End Mcrypt_module_close ($TD), $data = $this->removebr (Base64_encode ($data)); return $data;} Decrypt public Function decrypt ($encrypted) {$encrypted = Base64_decode ($encrypted); $key = Base64_decode ($this->key); $ td = Mcrypt_module_open (Mcrypt_3des, ' ', MCRYPT_MODE_CBC, ');//using mcrypt_3des algorithm, CBC mode Mcrypt_generic_init ($TD, $key, $ THIS->IV);//initial processing $decrypted = Mdecrypt_generic ($TD, $encrypted);//decryption Mcrypt_generic_deinit ($TD);//End Mcrypt_module_close ($TD); $decrypted = $this->removepadding ($decrypted); return $decrypted;} Fill password, padding to multiples of 8 public function padding ($str) {$len = 8-strlen ($str)% 8;for ($i = 0; $i < $len; $i + +) {$str. = Chr (0);} return $STR;} Delete shim public Function removepadding ($str) {$len = strlen ($str), $newstr = ""; $str = Str_split ($STR); for ($i = 0; $i < $len; $i + +) {if ($str [$i]! = Chr (0)) {$newstr. = $str [$i];}} return $NEWSTR;} Delete carriage return and newline public function Removebr ($str) {$len = strlen ($str), $newstr = ""; $str = Str_split ($STR); for ($i = 0; $i < $len; $i + +) {if ($str [$i]! = ' \ n ' and $str [$i]! = ' \ r ') {$newstr. = $str [$i];}} return $newstr;}} Test$input = "1QAZ2WS"; echo "plaintext:". $input. "
"; $crypt = new Crypt3des (); echo" Encode: ". $crypt->encrypt ($input)."
"; echo" Decode: ". $crypt->decrypt ($crypt->encrypt ($input));? >
Code can not look, just look inside a sentence: $td = Mcrypt_module_open (Mcrypt_3des, ", MCRYPT_MODE_CBC,"), the error is he.
I've searched for a whole bunch of solutions, and the right approach should be (for Windows systems only):
This error occurs when you use function Mcrypt_module_open to decrypt a server side that is running PHP that is missing libmcrypt.dll.
The following settings can be resolved on the server.
Download a PHP mcrypt module installation package on the Internet, only need to Libmcrypt.dll file (general website download, PHP directory already have)
1. Copy the Libmcrypt.dll to the System32 directory or the extensions directory under the PHP installation directory
2. Copy the Libmcrypt.dll to the bin directory of the Apache installation directory
3. Locate the php.ini file in the Windows directory, open it
4. Find; Directory in which the loadable Extensions (modules) reside.
Extension_dir = "./" such as: Extension_dir = "D:\php5\ext"
These two lines, to make Extension_dir point to the directory can find Libmcrypt.dll, or system path under the Libmcrypt.dll
5. Find; Windows Extensions entries below; Extension=php_mcrypt.dll this line and Extension=php_iconv.dll (my No, omitted) these two lines, remove the preceding semicolon
PS: Just start to look at the online solution, some said to modify the PHP installation directory under the php.ini, but after the modification is useless. Be sure to modify the php.ini! in the Windows directory
The above describes the PHP encryption 3DES error call to undefined function:mcrypt_module_open how to solve, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.