title: AES encrypt java and javascript different output
body: <p>Since a couple of days i try to figure out why i have in javascript(cryptojs) and java different encryption output. Im at a dead end and dont know what to change anymore, i think i will lose my head on this. This is the complete code and should be easy to copy paste for testing. You are my last hope. ^^</p>
  
  <pre><code>plainText = plaintext
  password = password
  salt = 3FF2EC019C627B945225DEBAD71A01B6985FE84C95A70EB132882F88C0A59A55
  iv = 3C46C00F42A6044A"
  </code></pre>
  
  <blockquote>
    <p>Javascript result = zbohHpV5RtmHiH3cKDY15w==</p>
    
    <p>Java result = wVdRQiIqkyVlttkWpCMSpQ==</p>
  </blockquote>
  
  <p><strong>Javascript html:</strong> updated and changed iterations to 10</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
          &lt;title&gt;Aes Test&lt;/title&gt;
          &lt;script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/pbkdf2.js"&gt;&lt;/script&gt;
          &lt;script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="result"&gt;&lt;/div&gt;
      &lt;/body&gt;
      &lt;script&gt;
  
  
  var password = "password";
  var salt = "3FF2EC019C627B945225DEBAD71A01B6985FE84C95A70EB132882F88C0A59A55";
  
  var plainText = "plaintext";
  var iv = "3C46C00F42A6044A";
  
  var key = CryptoJS.PBKDF2(password, CryptoJS.enc.Hex.parse(salt), {keySize: 128/32, iterations: 10});
  
  var a = CryptoJS.AES.encrypt(plainText, key, {iv: CryptoJS.enc.Hex.parse(iv)}).ciphertext.toString(CryptoJS.enc.Base64);
  
  
  var result = "encypted: " + a + "&lt;br \&gt;";
  document.getElementById("result").innerHTML = result;
      &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Java Main.class</strong></p>
  
  <pre><code>public class main {
  
      public static void main(String[] args) throws Exception {
          String result = Aes.encrypt("plaintext", "password", "3FF2EC019C627B945225DEBAD71A01B6985FE84C95A70EB132882F88C0A59A55", "3C46C00F42A6044A");
          System.out.println(result);    
      }  
  }
  </code></pre>
  
  <p><strong>Java Aes.class</strong></p>
  
  <pre><code>import java.io.UnsupportedEncodingException;
  import java.security.InvalidAlgorithmParameterException;
  import java.security.InvalidKeyException;
  import java.security.NoSuchAlgorithmException;
  import java.security.spec.InvalidKeySpecException;
  import java.security.spec.KeySpec;
  import javax.crypto.BadPaddingException;
  import javax.crypto.Cipher;
  import javax.crypto.IllegalBlockSizeException;
  import javax.crypto.NoSuchPaddingException;
  import javax.crypto.SecretKey;
  import javax.crypto.SecretKeyFactory;
  import javax.crypto.spec.IvParameterSpec;
  import javax.crypto.spec.PBEKeySpec;
  import javax.crypto.spec.SecretKeySpec;
  import org.apache.commons.codec.binary.Base64;
  
  public class Aes { 
      private static final int pswdIterations = 10;
      private static final int keySize =  128;
  
      public static String encrypt(String plainText, String password, String salt, String initializationVector) throws NoSuchAlgorithmException, InvalidKeySpecException, UnsupportedEncodingException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
          byte[] saltBytes = salt.getBytes("UTF-8");
          byte[] ivBytes = initializationVector.getBytes("UTF-8");
          Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
          SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
          KeySpec spec = new PBEKeySpec(password.toCharArray(), saltBytes, pswdIterations, keySize);
          SecretKey key = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES");
          cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(ivBytes));
          byte[] encryptedTextBytes = cipher.doFinal(plainText.getBytes());
          return new Base64().encodeAsString(encryptedTextBytes);
      } 
  }
  </code></pre>