View Full Version : Mcrypt not decrypting the first eight characters

06-15-2005, 01:27 PM
I am using the following to encrypt and decrypt a simple multiline string.

$riv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
$riv = mcrypt_create_iv($riv_size, MCRYPT_RAND);

if ($operation == 'decrypt')
$string = rtrim(mcrypt_decrypt(MCRYPT_BLOWFISH, $crypt_key, base64_decode($string), MCRYPT_MODE_CBC, $riv));
elseif ($operation == 'encrypt')
$string = base64_encode(mcrypt_encrypt(MCRYPT_BLOWFISH, $crypt_key, $string, MCRYPT_MODE_CBC, $riv));

However, upon decrypting the string, the first eight characters remain garbled as if they are still encrypted. This is the first time I have ever encountered this problem and I have used mcrypt before in other scripts without the first eight characters remaining encrypted. Why would this happen?

Currently I am having to pad the string with spaces to the left each time to get around this problem and then strip them after decrypting.