note 111049 added to function.mcrypt-create-iv
| From: | marcusatbolmstedtdotcom | Date: | Wed, 09 Jan 2013 14:42:02 +0000 |
| Subject: | note 111049 added to function.mcrypt-create-iv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192861@lists.php.net to get a copy of this message | ||
In response to "hans at llis dot nl":
Your example does generate a noise, you just made an error in your code example, and used
MCRYPT_RAND instead of MCRYPT_DEV_RANDOM when re-generating the IV.
Trying the following will result in random noise every time:
<?php
$td = mcrypt_module_open (MCRYPT_RIJNDAEL_256, "", MCRYPT_MODE_CBC, "");
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_DEV_RANDOM);
header("Content-type: image/png");
$img = imagecreatetruecolor(255,255);
$ink = imagecolorallocate($img,255,255,255);
for($i=0;$i<255;$i++) {
for($j=0;$j<255;$j++) {
$twobytes = substr ($iv, 0, 2);
$iv = substr ($iv, 2);
if (!strlen ($iv)) $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_DEV_RANDOM);
//Corrected
imagesetpixel($img, ord($twobytes[0]), ord($twobytes[1]), $ink);
}
}
imagepng($img);
imagedestroy($img);
?>
----
Server IP: 69.147.83.199
Probable Submitter: 94.142.229.4
----
Manual Page -- http://php.net/manual/en/function.mcrypt-create-iv.php
Edit -- https://master.php.net/note/edit/111049
Del: integrated -- https://master.php.net/note/delete/111049/integrated
Del: useless -- https://master.php.net/note/delete/111049/useless
Del: bad code -- https://master.php.net/note/delete/111049/bad+code
Del: spam -- https://master.php.net/note/delete/111049/spam
Del: non-english -- https://master.php.net/note/delete/111049/non-english
Del: in docs -- https://master.php.net/note/delete/111049/in+docs
Del: other reasons-- https://master.php.net/note/delete/111049
Reject -- https://master.php.net/note/reject/111049
Search -- https://master.php.net/manage/user-notes.php