I have write a code to encrypt a data with mcrypt. When I create a IV it works BUT when I decrypt it the decrypted text isn't the same as before and it gives me this error:
Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize
Here is my code when I create a IV:
$iv = mcrypt_create_iv(mcrypt_get_iv_size($algo, $type), MCRYPT_RAND);
The problem is also that it gives a string with unreadable characters.
Here is my code when encrypting:
trim(base64_encode(mcrypt_encrypt($algo, $pass,
$data, $type, $iv)));
And here is for decrypting:
trim(mcrypt_decrypt($algo, $pass,
base64_decode($data), $type, $iv));
The question: Why can't it decrypt so I get the plaintext and why it gives me a error.
EDIT: When I use a EMPTY IV, it works and I get the plaintext, but it still gives me error:
Warning: mcrypt_xxxxxx(): The IV parameter must be as long as the blocksize