i get the following error:
mcrypt_decrypt() [function.mcrypt-decrypt]: The IV parameter must be as long as the blocksize

using the class I wrote:
<?
///file :: CryptDecrypt.class.php
class CryptDecrypt{
public static function getCrypt($user, $secret) {
$cookieData = serialize( $user );
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
srand();
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encryptedData = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $secret, $cookieData, MCRYPT_MODE_CBC, $iv);
return base64_encode($encryptedData).':'.$iv;
}

public static function deCrypt($user, $secret) {
list($encryptedData,$iv) = explode(':', $user);
$rawData = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $secret, base64_decode($encryptedData), MCRYPT_MODE_CBC, $iv );
$user = unserialize( $rawData );
return $user;
}
}
?>
testing it with following code:
<?php
//file::testCryptDecrypt.php
require_once('CryptDecrypt.class.php'); //Crypt class
$key = "mykey";
$data = "Plaintext:hello";

echo "Original data: $data<br />";

$encrypt = 	CryptDecrypt::getCrypt( $data, $key)."<br/>";
echo "encrypted ". $encrypt;

$decrypt = CryptDecrypt::deCrypt( $encrypt, $key)."<br/>";
echo "decrypted" . $decrypt;

?>

Any suggestion?
thanks.....

    i'll answer myself

    the major problem is that I don't encode/decode base 64 the IV.... so sometime when IV value gets the same char i use as separator the explode mess up the thigs returning back a partial IV...

      Write a Reply...