<?php $phrase = 'secret message'; $key = 'KEY'; $encrypt = encrypt($key, $phrase); $phrase = decrypt($key, $encrypt); echo $encrypt, ' = ', $phrase; function encrypt($key, $text) { $cipher = mcrypt_module_open(MCRYPT_BLOWFISH,'','cbc',''); mcrypt_generic_init($cipher, $key, '12345678'); $encrypted = mcrypt_generic($cipher,$text); mcrypt_generic_deinit($cipher); $encrypted = bin2hex($encrypted); return $encrypted; } function decrypt($key, $encrypted) { $encrypted = hex2bin($encrypted); $cipher = mcrypt_module_open(MCRYPT_BLOWFISH,'','cbc',''); mcrypt_generic_init($cipher, $key, '12345678'); $decrypted = mdecrypt_generic($cipher,$encrypted); mcrypt_generic_deinit($cipher); return $decrypted; }
12345678 это размер блока, его можно задать произвольный, не задавать вообще (0) или сгенерить через mcrypt_enc_get_iv_size