note 19669 deleted from function.mcrypt-cfb by sander

From: Date: Tue, 14 May 2002 18:34:20 +0000
Subject: note 19669 deleted from function.mcrypt-cfb by sander
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-30640@lists.php.net to get a copy of this message
Here is my example that I have gotten working, however I do not know how 'secure' it is, seeing how there is very little regarding this area of PHP in the first place :( The only thing is this: I could not for the life of me get this function working with the $iv parameter. It just *would not* decode properly. Took the $iv out, worked like a charm. function encrypt($key, $plain_text) { // returns encrypted text // incoming: should be the $key that was encrypt // with and the $plain_text that wants to be encrypted $plain_text = trim($plain_text); $c_t = @mcrypt_cfb (MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT); return trim(chop(base64_encode($c_t))); } function decrypt($key, $c_t) { // incoming: should be the $key that you encrypted // with and the $c_t (encrypted text) // returns plain text // decode it first :) $c_t = trim(chop(base64_decode($c_t))); $p_t = @mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT); return trim(chop($p_t)); } **NOTE: I am using base64_de/encode for the purpose of storing in MySQL and files and printing via the web / storing in input boxes. Another option is bin2hex.

« previous php.notes (#30640) next »