note 19669 added to function.mcrypt-cfb
| From: | fandelem at hotmail dot com | Date: | Thu, 07 Mar 2002 07:09:47 +0000 |
| Subject: | note 19669 added to function.mcrypt-cfb | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27456@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.
--
http://www.php.net/manual/en/function.mcrypt-cfb.php
http://master.php.net/manage/user-notes.php?action=edit+19669
http://master.php.net/manage/user-notes.php?action=delete+19669
http://master.php.net/manage/user-notes.php?action=reject+19669