I’m trying to post multiple encrypted strings to a .php file which uses a foreach loop to decrypt them with mcrypt. If I comment out the line to decrypt the strings, it shows each $item unencrypted as it should. If I use either of the methods I have here for decrypting the string, it decrypts only the first one then abruptly stops. No error, nothing in the error logs. Both methods produce the same results. What am I doing wrong???
Thanks in advance.
[php]
$key = ‘TestKey’;
$iv = ‘abcdefghijklmnop’;
$bit_check=8;
function decrypt($encrypted_text,$key,$iv,$bit_check)
{
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128,’’,‘ecb’,’’);
mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mdecrypt_generic($cipher,base64_decode($encrypted_text));
mcrypt_generic_deinit($cipher);
$last_char=substr($decrypted,-1);
for($i=0;$i<$bit_check-1; $i++)
{
if(chr($i)==$last_char)
{
$decrypted=substr($decrypted,0,strlen($decrypted)-$i);
break;
}
}
mcrypt_module_close($cipher);
return $decrypted;
}
foreach ($_POST[‘id’] as $item)
{
echo $item."\n\r";
echo decrypt($item,$key,$iv,$bit_check)."\n\r";
//echo mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$key,base64_decode($item),MCRYPT_MODE_ECB,$iv)."\n";
}
[/php]