Can not create an IV with a size of less then 1 or

Hello !

I don’t have help from french forum so I will try here. Sorry for my bad english!

I tried a test.php file to crypt… (example)

[php]$string = “Some text to be encrypted”;
$secret_key = “k4Mdj9Ka8Kam2kMxn2jMdj0KA2”;

// Encryption Algorithm
$etype = MCRYPT_RIJNDAEL_256;

// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($etype, MCRYPT_MODE_ECB), MCRYPT_RAND);

// Output original string
PRINT "Original string: $string

";

// Encrypt $string
$encrypted_string = mcrypt_encrypt($etype, $secret_key, $string, MCRYPT_MODE_CBC, $iv);

// Convert to hexadecimal and send to browser
PRINT “Encrypted string: “.BIN2HEX($encrypted_string).”

”;

$decrypted_string = mcrypt_decrypt($etype, $secret_key, $encrypted_string, MCRYPT_MODE_CBC, $iv);

PRINT “Decrypted string is: $decrypted_string”[/php]

It work!

Next, I tried to put in my class “Secure” :

[php]class Secure {
const Cle = ‘blablabla’; // key
const etype = MCRYPT_RIJNDAEL_256;

function Crypter($etype,$secret_key,$string) //Crypt
{
$iv = mcrypt_create_iv(mcrypt_get_iv_size($etype, MCRYPT_MODE_ECB), MCRYPT_RAND);
return bin2hex(mcrypt_encrypt($etype, $secret_key, $string, MCRYPT_MODE_CBC, $iv));
}

function Decrypt($etype,$secret_key,$encrypted_string)
{
$iv = mcrypt_create_iv(mcrypt_get_iv_size($etype, MCRYPT_MODE_ECB), MCRYPT_RAND);
return mcrypt_decrypt($etype, $secret_key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
}[/php]

And, to register a member, I have a class “Member” :

[php]$pseudo = Secure::Crypter($this->etype,$this->Cle,$pseudo);
$email = Secure::Crypter($this->etype,$this->Cle,$email);[/php]

Conlusion, It doesn’t work! I don’t understand because the script is exactly the same. Where is the mistake ? I have this warning :

Warning: mcrypt_get_iv_size() [function.mcrypt-get-iv-size]: Module initialization failed in /home/public_html/class/Secure.php on line 162

Warning: mcrypt_create_iv() [function.mcrypt-create-iv]: Can not create an IV with a size of less then 1 or greater then 2147483647 in /home/public_html/class/Secure.php on line 162

Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: Module initialization failed in /home/public_html/class/Secure.php on line 163

Warning: mcrypt_get_iv_size() [function.mcrypt-get-iv-size]: Module initialization failed in /home/public_html/class/Secure.php on line 162

I don’t really understand mcrypt, iv etc. I would like to crypt and uncrypt string without any problèms.

Thank a lot for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service