I have a string encrypted with AES in Counter mode, it wasn't done with PHP and I can't make mcrypt to decode it :( there's a class that works as expected: http://www.movable-type.co.uk/scripts/aes.html (see bottom of the page), but it's slow so I want to decrypt with mcrypt.
According to classes decrypt
method I did following:
$key = $_POST['key'];
$length = strlen($key);
if($length > 32)
$key = substr($key, 0, 32);
$cyphered = base64_decode($_POST['cyphered']);
/// make initialization vector with first 8 bytes treated as integers
$f8b = array_map('ord', str_split(substr($cyphered, 0, 8)));
array_unshift($f8b, 'I8');
$iv = call_user_func_array('pack', $f8b);
print mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, substr($cyphered, 8), 'ctr', $iv);
And result is garbage on output :( I don't understand what am I doing wrong. Could somebody please sched some light on this problem?