0

I want to recive same encrypting result by using AES with PHP and JAVA but in PHP mcrypt need 32 bytes length Initialize vector and in Java i can use only 16 bytes length IV (Exception in thread "main" java.security.InvalidAlgorithmParameterException: Wrong IV length: must be 16 bytes long)even with unlimited strength policy how coudl i make compatible Java AES with PHP ?

$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', 'ctr', '');
$iv_size = mcrypt_enc_get_iv_size($cipher);

$key = '***';
$iv =  hex2str('00000001040506070000000000000001');


// Encrypt
if (mcrypt_generic_init($cipher, $key, $iv) != -1)
{
    $encrypted = mcrypt_generic($cipher, $text);
    mcrypt_generic_deinit($cipher);

    echo '<strong>After encryption:</strong> ' . bin2hex($encrypted) . '<br />';
}

in java im using encryptCipher = Cipher.getInstance("AES/CTR/PKCS5Padding")

Sammitch
  • 30,782
  • 7
  • 50
  • 77
whd
  • 1,819
  • 1
  • 21
  • 52
  • PHP's AES, aka rijndael-128, requires a 16-byte IV. Are you certain you've got the right algorithm? – Sammitch May 27 '14 at 23:46
  • i have posted some of my code – whd May 27 '14 at 23:51
  • I'm not a Java expert, but I think you've got the wrong algo there. See [this answer](http://stackoverflow.com/a/9334357/1064767) to extract a listing out of your system. Also, I'm not a crypto expert, but you probably shouldn't post your keys on the internet. :I – Sammitch May 28 '14 at 00:00
  • I don't think you can use only 16 bytes length IV in java. Why are you not posting you java code clearly as you are doing with php while your question is on java. – gyanu May 28 '14 at 00:38

0 Answers0