Hello Member,
I think PHP mcrypt function uses a zero byte padded input string. So in your java code set the transformation as AES/CBC/NoPadding and then pad the input string with 0. Following code snippets yields identical results.
PHP Code
<?php
$plaintext = "muthu";
$key256 = "12345678901234561234567890123456";
$iv = "1234567890123456";
$plaintext_utf8 = utf8_encode($plaintext);
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', $iv);
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key256, $plaintext_utf8, MCRYPT_MODE_CBC, $iv);
echo base64_encode($ciphertext);
?>
Java Code
String strKey = "12345678901234561234567890123456";
byte[] arrKey = strKey.getBytes("UTF-8");
byte[] ivKey = new byte[16];
byte[] bytIn = new byte[] {'m', 'u', 't', 'h', 'u', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
System.arraycopy(arrKey, 0, ivKey, 0, 16);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(arrKey, "AES"), new IvParameterSpec(ivKey));
byte[] enc = cipher.doFinal(bytIn);
return new String(Base64.encodeBase64(enc));
Regards,