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")