The mcrypt_cbc function encrypts a string using cipher block chaining. This method
is best suited to encrypting whole files. The algorithm argument is one of the constants
listed in Table 9.8. The mode argument can be either MCRYPT_DECRYPT or
MCRYPT_ENCRYPT. An initialization vector is optional. Remember that if you encrypt
using one, you must use the same one to decrypt.
<?
//set up test data
$message = "This message is sensitive.";
$key = "secret";
//encrypt message
$code = mcrypt_ofb(MCRYPT_BLOWFISH_128, $key,
$message, MCRYPT_ENCRYPT);
//pring decrypted message
print(mcrypt_ofb(MCRYPT_BLOWFISH128, $key, $code,
MCRYPT DECRYPT));
?>
mcrypt_cfb(integer algorithm, string key, string data, integer
mode, string initialization_vector)
The mcrypt_cfb function encrypts a string using cipher feedback. This method is best
suited to encrypting streams. However, PHP's mcrypt interface does not support stream
ciphers at the time of this writing. The algorithm argument is one of the constants listed
in Table 9.8. The mode argument can be either MCRYPT_DECRYPT or
MCRYPT_ENCRYPT. An initialization vector is required. You must use the same one to
decrypt.
mcrypt_ecb(integer algorithm, string key, string data, integer
mode)
The mcrypt_ecb function encrypts a string using the electronic codebook method,
which is good for encryption of short, irregular data. The algorithm argument is one of
the constants listed in Table 9.8. The mode argument can be either
MCRYPT_DECRYPT or MCRYPT_ENCRYPT.
<?
//set up test data
$message = "This message is sensitive.";
$key = "secret";