Check the Phpinfo () page to see which version of your libmcrypt is. if it is 2.4.0 or later, you cannot use your method. In addition, libmcrypt's supported encryption algorithms depend on different libmcrypt versions. The following is the 2.4.0 + encryption and decryption method ~ It is also an example of PHP code in the manual: functionmake_seed () {view the Phpinfo () page to see which version of your libmcrypt is. if it is later than 2.4.0, you cannot use your method.
In addition, libmcrypt's supported encryption algorithms depend on different libmcrypt versions.
The following is the 2.4.0 + encryption and decryption method ~
It is also an example in the manual.
PHP code:
Function make_seed (){
List ($ usec, $ sec) = explode ('', microtime ());
Return (float) $ sec + (float) $ usec * 100000 );
}
Srand (make_seed ());
/* Enable the encryption algorithm /*/
$ Td = mcrypt_module_open ('twofish ', '', 'ECB ','');
/* Create an IV and check the key length */
$ Iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ td), MCRYPT_RAND );
$ Ks = mcrypt_enc_get_key_size ($ td );
/* Generate the key */
$ Key = substr (md5 ('very secret key'), 0, $ ks );
/* Initialize the encryption program */
Mcrypt_generic_init ($ td, $ key, $ iv );
/* Encrypted, $ encrypted stores encrypted data */
Print $ encrypted = mcrypt_generic ($ td, 'This is very important data ');
/* Check the encryption handle */
Mcrypt_generic_deinit ($ td );
/* Initialize the encryption module for decryption */
Mcrypt_generic_init ($ td, $ key, $ iv );
/* Decrypt */
$ Decrypted = mdecrypt_generic ($ td, $ encrypted );
/* Check the decryption handle and close the module */
Mcrypt_generic_deinit ($ td );
Mcrypt_module_close ($ td );
/* Display the original string */
Echo trim ($ decrypted). "\ n ";