title: Different AES128 with zero padding encryption result between php and java
body: <p>I have a different result between java and php method in doing AES128 with zero padding and no IV encryption.</p>
  
  <p>Here PHP code :</p>
  
  <pre><code>&lt;?php
  $ptaDataString = "secretdata";
  $ptaDataString = encryptData($ptaDataString);
  $ptaDataString = base64_encode($ptaDataString);
  function encryptData($input) {
                  $ptaKey = 'secret'; 
                  $iv = "\0";
                  $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $ptaKey, $input, MCRYPT_MODE_CBC, $iv);
                  return $encrypted;
  }
  echo $ptaDataString;
  ?&gt;
  </code></pre>
  
  <p>And here is java code:</p>
  
  <pre><code>public static String encrypt() throws Exception {
      try {
          String data = "secretdata";
          String key = "secret0000000000";
          String iv = "0000000000000000";
  
          Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
          int blockSize = cipher.getBlockSize();
  
          byte[] dataBytes = data.getBytes();
          int plaintextLength = dataBytes.length;
          if (plaintextLength % blockSize != 0) {
              plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
          }
  
          byte[] plaintext = new byte[plaintextLength];
          System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
  
          SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
          IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
  
          cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
          byte[] encrypted = cipher.doFinal(plaintext);
  
          return new sun.misc.BASE64Encoder().encode(encrypted);
  
      } catch (Exception e) {
          e.printStackTrace();
          return null;
      }
  }
  </code></pre>
  
  <p><strong>php resulting : kjgE5p/3qrum6ghdjiVIoA==</strong></p>
  
  <p><strong>Java resulting : zLKhVMksRRr1VHQigmPQ2Q==</strong></p>
  
  <p>Any help would be appreciated,
  Thanks</p>