开发者

PHP AES decryption

I'm really struggling to decrypt a given cipher text in PHP and I'm hoping that one of you will be able to spot where I'm going wrong with this one.

So this is the string I'm trying to decode

Wq+J2IlE7Cug1gJNiwy1beIcFggGhn+gZHkTCQ4J/DR3OY45OMs4RXN850xbfAmy

I know its encrypted with AES/CBC/PKCS5Padding with an IV of

2ZqVSHjqn3kMump0rvd8AA==

and I'll email you the key upon request.

public static function aes128cbcDecrypt($key, $encrypted_text, $iv) 
{
  $td = mcrypt_module_open(MCRYPT_RIJNDAEL_192, '', MCRYPT_MODE_CBC, '');
  mcrypt_generic_init($td, $key, $iv);
  $decrypted = mdecrypt_generic($td, $encrypted_text);
  mcrypt_generic_deinit($td);
  mcrypt_module_close($td);
  return trim($decrypted);
}

When I've tried running this I get complete gibberish

ã5‡³/.3p›¤ý°$² —ïÅ»<9 ‘m ê|Ÿ.ÂYº|Šû^w¬¾‚=l“½·F›Vá开发者_如何学JAVArsT~ê H�ÿfß]7ñH

Equally, when I encrypt the known plain text, I get a load of gibberish instead of the ascii string that its meant to be.

† —4†º¢V�Öæƒ{ Zsöœl ò°Þ 
PegöE&£á=Ǻ܀

Have any of you got any ideas as where I'm going wrong?


Maybe a stupid question, but should the IV not be base64-decoded before it is used?

$realIV = base64_decode($iv);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜