By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

mcrypt_enc_get_iv_size not working

P: n/a
mcrypt_enc_get_iv_size is not randomizing the vector. I have tried to
randomize the seed in various ways but it always returns the same output.

My current code as follows:

for($i = 1; $i < 5; $i++)
{
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));

$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->CryptRes),
MCRYPT_RAND);
echo $iv."<br/>\n";
}

It outputs the same string each time.
Any ideas?

Thanks,
Jon
May 31 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Of course I meant mcrypt_create_iv...
May 31 '07 #2

P: n/a
C.
On 31 May, 19:27, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
Of course I meant mcrypt_create_iv...
Code looks OK.

Are you getting a sensible value for mcrypt_enc_get_iv_size($this-
>CryptRes) ?
Have you tried using the devices as an entropy source?

IIRC mcrypt uses binary strings, in some cases it even assigns C
strings to PHP strings; it might be a better idea to encode the output
before writing to the console/browser:

echo base64_encode($iv) ."<br/>\n";

C.

May 31 '07 #3

P: n/a

"C." <co************@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
On 31 May, 19:27, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
>Of course I meant mcrypt_create_iv...

Code looks OK.

Are you getting a sensible value for mcrypt_enc_get_iv_size($this-
>>CryptRes) ?
yeah, its a bug in mcrypt and I randomized the string it returned myself.
Have you tried using the devices as an entropy source?

IIRC mcrypt uses binary strings, in some cases it even assigns C
strings to PHP strings; it might be a better idea to encode the output
before writing to the console/browser:

echo base64_encode($iv) ."<br/>\n";
Well, it was just for a test.. in reality there is no writing to the
console. Was just trying to figure why my strings were not being randomized.

Thanks,
Jon
May 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.