<?PHP/*turn on encryption algorithms and patterns*/ $TD= Mcrypt_module_open (' rijndael-256 ', ' ', ' ofb ', '); /*creates an initial vector and detects the key length. * Windows platform please use Mcrypt_rand. */ $iv= Mcrypt_create_iv (Mcrypt_enc_get_iv_size ($TD),mcrypt_dev_random); $ks= Mcrypt_enc_get_key_size ($TD); /*Create key*/ $key=substr(MD5(' Very secret key '), 0,$ks); /*Initializing Encryption*/Mcrypt_generic_init ($TD,$key,$iv); /*Encrypt Data*/ $encrypted= Mcrypt_generic ($TD, ' This is very important data '); /*end encryption, perform cleanup work*/Mcrypt_generic_deinit ($TD); /*initial dissolve secret module*/Mcrypt_generic_init ("T",$key,$iv); /*Decrypt Data*/ $decrypted= Mdecrypt_generic ($TD,$encrypted); /*end decryption, perform cleanup work, and close the module*/Mcrypt_generic_deinit ($TD); Mcrypt_module_close ($TD); /*display text*/ Echo Trim($decrypted) . "\ n";?>
Encryption and decryption module in PHP-mcrypt