title: Implement encrypt function from crypto-js library in Java
body: <p><a href="https://github.com/brix/crypto-js" rel="nofollow noreferrer">crypto-js</a> is used by javascript developers to encrypt text. Its simple to use.  </p>
  
  <pre><code>var CryptoJS = require("crypto-js");
  
  // Encrypt
  var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123');
  
  // Decrypt
  var bytes  = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123');
  var plaintext = bytes.toString(CryptoJS.enc.Utf8);
  
  console.log(plaintext);
  </code></pre>
  
  <p>In this example <em>encrypt</em> function is taking only two arguments messageToEncrypt and salt. Rest of the configuration would be inside its definition. I am not a javascript guy so its difficult to find and understand <em>encrypt</em> definition.   </p>
  
  <p>I want to achieve same <code>AES</code> encryption using java. So for same input argument e.g. messageToEncrypt and salt I should get same encrypted text using crypto-js library and Java implementation.  </p>
  
  <p>I tried <code>javax.crypto</code> by exploring some links on google.  </p>
  
  <pre><code>String plainText = "messageToEncrypt";
  String key = "mySalt";
  SecretKey secKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
  Cipher aesCipher = Cipher.getInstance("AES");
  aesCipher.init(Cipher.ENCRYPT_MODE, secKey);
  byte[] x = aesCipher.doFinal(plainText.getBytes());
  System.out.println(x);
  </code></pre>
  
  <p>But this is not working for me because I dont know exact parameters like keySize and iterationCount.  </p>
  
  <p>I tried to use <a href="https://github.com/mpetersen/aes-example/blob/master/src/main/java/org/cloudme/sample/aes/AesUtil.java" rel="nofollow noreferrer">https://github.com/mpetersen/aes-example/blob/master/src/main/java/org/cloudme/sample/aes/AesUtil.java</a> also but again I am not sure about keySize and iterationCount.  </p>
  
  <p>How can I create simple exact implementation of crypto-js's AES encryption in java?</p>