I am also a novice php, through the W3cschool understand the basic principles of PHP after the write. But still a rookie.
First regardless of the 3DES encryption method is correct, the method is online, in the run when a mistake, the younger brother died. Look for it and finally find the way.
<?php/** * * php 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 '; public $iv = "23456789";//like
Java:private static byte[] Myiv = {50, 51, 52, 53, 54, 55, 56, 57}; Encrypt public Function Encrypt ($input) {$input = $this->padding ($input); $key = Base64_decode ($this->key); $TD = MC
Rypt_module_open (Mcrypt_3des, ', MCRYPT_MODE_CBC, ');
Using the 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 the mcrypt_3des algorithm, CBC mode Mcrypt_generic_init ($TD, $key, $this->iv); Initial processing $decrypted = Mdecrypt_generic ($TD, $encrypted);
Decryption of Mcrypt_generic_deinit ($TD);
End Mcrypt_module_close ($TD);
$decrypted = $this->removepadding ($decrypted);
return $decrypted; //Fill password, multiples of 8 public function padding ($str) {$len = 8-strlen ($str)% 8; for ($i = 0; $i < $len; $i + +) {$st
R. = chr (0);
return $str;
}//Delete filler 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. "
<br/> ";
$crypt = new Crypt3des (); echo "Encode:". $crypt->encrypt ($input). "
<br/> "; echo "Decode:". $crypt->decrypt ($crypt->encrypt ($input));Gt
Code can not look, just look inside the sentence: $TD = Mcrypt_module_open (Mcrypt_3des, ', MCRYPT_MODE_CBC, ');
I searched for a whole bunch of solutions, and the right approach would be (for Windows only):
This error occurs when a function mcrypt_module_open is used to decrypt when the server side running PHP is missing libmcrypt.dll.
Make the following settings on the server to resolve.
Download a PHP mcrypt module installation package on the Internet, only need Libmcrypt.dll files (general official online download, PHP directory already have)
1. Copy the Libmcrypt.dll to the extensions directory under the system32 directory or the PHP installation directory
2. Copy the Libmcrypt.dll to the Apache installation directory in the bin directory
3. Locate the php.ini file in the Windows directory and 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 the Extension_dir point to the directory can find Libmcrypt.dll, or system path under the Libmcrypt.dll
5. Find; Windows Extensions below; Extension=php_mcrypt.dll this line and; Extension=php_iconv.dll (mine not, omitted) these two lines, remove the preceding semicolon
PS: Just start to look at the online solution, and some say modify the PHP installation directory under the php.ini, but the modification is useless. Be sure to modify the php.ini! in the Windows directory