note 21479 added to function.mcrypt-encrypt
| From: | fandelem at hotmail dot com | Date: | Tue, 14 May 2002 18:01:15 +0000 |
| Subject: | note 21479 added to function.mcrypt-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30638@lists.php.net to get a copy of this message | ||
here is an example of using this function in cfb mode:
function encrypt_normal($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);
/*
We need a way to generate a _unique_ initialization vector
but at the same time, be able to know how to gather our IV at both
encrypt/decrypt stage. My personal recommendation would be
(if you are working with files) is to get the md5() of the file.
In this example, however, I want more of a broader scope, so I chose
to md5() the key, which should be the same both times. Note that the IV
needs to be the size of our algorithm, hence us using substr.
*/
/* generate an initialization vector */
$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
/* now we do our normal encrypting */
$c_t = mcrypt_encrypt (MCRYPT_CAST_256, $key, $plain_text, "cfb", $iv);
return trim(chop(base64_encode($c_t)));
}
--
http://www.php.net/manual/en/function.mcrypt-encrypt.php
http://master.php.net/manage/user-notes.php?action=edit+21479
http://master.php.net/manage/user-notes.php?action=delete+21479
http://master.php.net/manage/user-notes.php?action=reject+21479