Please wait while we load your page...


PHP Manual :: Examples

Mcrypt ciphers || Mcrypt Functions || Mcrypt || PHP Manual

Mcrypt can be used to encrypt and decrypt using the above mentioned ciphers. If you linked against libmcrypt-2.2.x, the four important mcrypt commands (mcrypt_cfb(), mcrypt_cbc(), mcrypt_ecb(), and mcrypt_ofb()) can operate in both modes which are named MCRYPT_ENCRYPT and MCRYPT_DECRYPT, respectively.

If you linked against libmcrypt 2.4.x or 2.5.x, these functions are still available, but it is recommended that you use the advanced functions.

Example #1 Encrypt an input value with AES with a 256-bit key under 2.4.x and higher in CBC mode

hash('sha256''this is a secret key'true);
$input "Let us meet at 9 o'clock at the secret place.";
$td mcrypt_module_open('rijndael-128''''cbc''');
$iv mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_URANDOM);
$encrypted_data mcrypt_generic($td$input);
This example will give you the encrypted data as a string in $encrypted_data. For a full example see mcrypt_module_open().

Mcrypt ciphers || Mcrypt Functions || Mcrypt || PHP Manual
Live Chat Not Available