note 111049 deleted from function.mcrypt-create-iv by danbrown
| From: | danbrown@php.net | Date: | Thu, 17 Jan 2013 15:17:25 +0000 |
| Subject: | note 111049 deleted from function.mcrypt-create-iv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193168@lists.php.net to get a copy of this message | ||
Note Submitter: marcus at bolmstedt dot com
----
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);
?>