I've been doing much searching but can't find an adequate explanation for why this:
public class encryption_test {
private static final String text_encoding = "UTF-8";
private byte [] byte_array (String input) throws Exception {
return input.getBytes (text_encoding);
}// byte_array;
private byte [] encrypt (String text) throws Exception {
Cipher cypher = Cipher.getInstance ("AES/CBC/PKCS5Padding");
Key key = new SecretKeySpec (byte_array ("12345678123456781234567812345678"), "AES");
cypher.init (Cipher.ENCRYPT_MODE, key, new IvParameterSpec (byte_array ("1234567812345678")));
return cypher.doFinal (byte_array (text));
}// encrypt;
public String doit () throws Exception {
byte [] etext = encrypt ("this is a plain string.");
return new String (Base64.getEncoder ().encode (etext));
}// doit;
}// encryption_test;
in Java, yields:
dAza6vYiYzJ9W/i4zPHVfvA8UUyw8Sq1g2YjuLt3EjI=
Whereas:
base64_encode (mcrypt_encrypt (MCRYPT_RIJNDAEL_128, "12345678123456781234567812345678", "This is a plain string.", MCRYPT_MODE_CBC, "1234567812345678"))
in PHP yields:
G+tdEOfQTtVCQGxW3N5uzkqN207OyfIPxS6zf2xrKKY=
According to everything I've read in the forums, they should both return the same thing. Can anyone please help me?
T. It works fine after you fix that.