Blowfish Cipher Tutorials - Herong's Tutorial Examples - v2.03, by Herong Yang
What is PHP Mcrypt Extension
This section describes the PHP Mcrypt Extension - a built-in PHP extension that allows to access the mcrypt library, which supports Blowfish and a number of other cipher encryption algorithms.
What is PHP Mcrypt Extension? PHP Mcrypt Extension is a built-in PHP extension that allows to access the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes.
PHP Mcrypt Extension is marked as "DEPRECATED in PHP 7.1.0, and REMOVED in PHP 7.2.0". You may consider to Sodium or OpenSSL extensions.
There are a number of ways to use PHP Mcrypt Extension for Blowfish cipher encryption:
1. Calling mcrypt_ecb(), mcrypt_cbc(), mcrypt_cfb(), or mcrypt_ofb() functions. But they are DEPRECATED and REMOVED in PHP 7.0.0.
$cipher = mcrypt_ecb(MCRYPT_BLOWFISH, $key, $data, MCRYPT_ENCRYPT); $cipher = mcrypt_cbc(MCRYPT_BLOWFISH, $key, $data, MCRYPT_ENCRYPT, $iv); $cipher = mcrypt_cfb(MCRYPT_BLOWFISH, $key, $data, MCRYPT_ENCRYPT, $iv); $cipher = mcrypt_ofb(MCRYPT_BLOWFISH, $key, $data, MCRYPT_ENCRYPT, $iv);
2. Calling the mcrypt_decrypt() function:
$cipher = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_ECB); $cipher = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_CBC, $iv); $cipher = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_CFB, $iv); $cipher = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_OFB, $iv);
3. Calling mcrypt_module_open(), mcrypt_generic_init(), mcrypt_generic(), mcrypt_generic_deinit(), and mcrypt_module_close() functions:
$obj = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); mcrypt_generic_init($obj, $key, $iv); $cipher = mcrypt_generic($obj, $data); mcrypt_generic_deinit($obj); mcrypt_module_close($obj);
See "Mcrypt - PHP Extension" Web page at http://php.net/manual/en/book.mcrypt.php for more information.
Table of Contents
OpenSSL "enc -bf-ecb" for Blowfish/ECB Encryption
OpenSSL "enc -bf-cbc" for Blowfish/CBC Encryption
OpenSSL "enc -bf-cfb" for Blowfish/CFB Encryption
OpenSSL "enc -bf-ofb" for Blowfish/OFB Encryption
►PHP Mcrypt Extension for Blowfish
PHP Mcrypt Blowfish Block Cipher
Mycrypt Blowfish Block Chaining Cipher
"ncfb/nofb" for Block Chaining Ciphers
Performing CFB Operation Manually