title: AES256 on Java vs PHP
body: <p>Quick one that's thus far been evading me (long night). I'm comparing AES256 in PHP vs Java and noticing discrepancies. Please for simplicity ignore the ascii key and the null IV, those will be replaced in production. But I need to get past this first and can't figure out where I am erring:</p>
  
  <p>PHP:</p>
  
  <pre><code>echo base64_encode(
      mcrypt_encrypt(
          MCRYPT_RIJNDAEL_128,
          "1234567890ABCDEF1234567890ABCDEF",
          "This is a test",
          MCRYPT_MODE_CBC,
          "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
      )
  );
  </code></pre>
  
  <p>Java</p>
  
  <pre><code>byte[] key = "1234567890ABCDEF1234567890ABCDEF".getBytes("UTF-8");
  byte[] iv  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
  SecretKeySpec newKey = new SecretKeySpec(key, "AES");
  Cipher cipher = Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE, newKey, ivSpec);
  byte[] results = cipher.doFinal("This is a test".getBytes("UTF-8"));
  
  return Base64.encodeToString(results,Base64.DEFAULT);
  </code></pre>
  
  <p>PHP output:  <code>0KwK+eubMErzDaPU1+mwTQ==</code></p>
  
  <p>Java output: <code>DEKGJDo3JPtk48tPgCVN3Q==</code></p>
  
  <p>Not quite what I was expecting o_O !</p>
  
  <p>I've also tried <code>MCRYPT_MODE_CBC</code>, <code>MCRYPT_MODE_CFB</code>, <code>MCRYPT_MODE_ECB</code>, <code>MCRYPT_MODE_NOFB</code>, etc.. none of them produced the Java string.</p>