PHP uses DES for encryption and decryption. DES is a standard data encryption algorithm. for details about this algorithm, refer to Wikipedia and Baidu: Wikipedia & nbsp; & nbsp; there is an extension in Baidu Encyclopedia php that supports the DES encryption algorithm. it is: extension = php_mcrypt.dll. in the configuration file, this extension is played in PHP and DES is used for encryption and decryption.
DES is a standard data encryption algorithm. for details about this algorithm, refer to Wikipedia and Baidu Encyclopedia:
Wiki encyclopedia Baidu Encyclopedia
There is an extension in php that supports the DES encryption algorithm: extension = php_mcrypt.dll
Opening the extension in the configuration file cannot be used in windows.
You need to copy libmcrypt. dll in the PHP folder to the system32 directory of the system. through phpinfo, you can see that mcrypt indicates that this module can be used properly.
The following is an example of using DES for encryption and decryption in PHP:
// $ Input-stuff to decrypt
// $ Key-the secret key to use
Function do_mencrypt ($ input, $ key)
{
$ Input = str_replace ("" n "," ", $ input );
$ Input = str_replace ("" t "," ", $ input );
$ Input = str_replace ("" r "," ", $ input );
$ Key = substr (md5 ($ key), 0, 24 );
$ Td = mcrypt_module_open ('tripledes ', '', 'ECB ','');
$ Iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ td), MCRYPT_RAND );
Mcrypt_generic_init ($ td, $ key, $ iv );
$ Encrypted_data = mcrypt_generic ($ td, $ input );
Mcrypt_generic_deinit ($ td );
Mcrypt_module_close ($ td );
Return trim (chop (base64_encode ($ encrypted_data )));
}
// $ Input-stuff to decrypt
// $ Key-the secret key to use
Function do_mdecrypt ($ input, $ key)
{
$ Input = str_replace ("" n "," ", $ input );
$ Input = str_replace ("" t "," ", $ input );
$ Input = str_replace ("" r "," ", $ input );
$ Input = trim (chop (base64_decode ($ input )));
$ Td = mcrypt_module_open ('tripledes ', '', 'ECB ','');
$ Key = substr (md5 ($ key), 0, 24 );
$ Iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ td), MCRYPT_RAND );
Mcrypt_generic_init ($ td, $ key, $ iv );
$ Decrypted_data = mdecrypt_generic ($ td, $ input );
Mcrypt_generic_deinit ($ td );
Mcrypt_module_close ($ td );
Return trim (chop ($ decrypted_data ));
}