note 88687 added to function.mcrypt-encrypt
| From: | KaiSellgren at osu1 dot php dot net | Date: | Tue, 03 Feb 2009 20:12:15 +0000 |
| Subject: | note 88687 added to function.mcrypt-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150165@lists.php.net to get a copy of this message | ||
bantam (below) has written a bad example.
He was base64 decoding even though he never base64 encoded.
In addition to that, the trimming is not effective and the cipher block mode is not secure.
Here is a very good approach to encrypt / decrypt data.
<?php
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size,MCRYPT_RAND);
$key = "my secret key";
$text = "I discovered a way to crack into the White House."; // Just kidding :P
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key,$text, MCRYPT_MODE_CBC,$iv);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key,$crypttext, MCRYPT_MODE_CBC,$iv);
echo rtrim($decrypttext,"\0");
?>
----
Server IP: 62.237.7.3
Probable Submitter: 81.175.154.102
----
Manual Page -- http://www.php.net/manual/en/function.mcrypt-encrypt.php
Edit -- https://master.php.net/note/edit/88687
Del: integrated -- https://master.php.net/note/delete/88687/integrated
Del: useless -- https://master.php.net/note/delete/88687/useless
Del: bad code -- https://master.php.net/note/delete/88687/bad+code
Del: spam -- https://master.php.net/note/delete/88687/spam
Del: non-english -- https://master.php.net/note/delete/88687/non-english
Del: in docs -- https://master.php.net/note/delete/88687/in+docs
Del: other reasons-- https://master.php.net/note/delete/88687
Reject -- https://master.php.net/note/reject/88687
Search -- https://master.php.net/manage/user-notes.php