title: AES encryption using Java and decryption using Javascript
body: <p>I am making an application which needs Java based AES Encryption and JavaScript based decryption.
  I am using the following code for encryption as a basic form.</p>
  
  <pre><code>public class AESencrp {
  
    private static final String ALGO = "AES";
    private static final byte[] keyValue = 
        new byte[] { 'A', 'b', 'c', 'd', 'e', 'f', 'g',
        'h', 'i', 'j', 'k','l', 'm', 'n', 'o', 'p'};
  
    public static String encrypt(String Data) throws Exception {
      Key key = generateKey();
      Cipher c = Cipher.getInstance(ALGO);
      c.init(Cipher.ENCRYPT_MODE, key);
      byte[] encVal = c.doFinal(Data.getBytes());
      String encryptedValue = new BASE64Encoder().encode(encVal);
      return encryptedValue;
    }
  
  
    private static Key generateKey() throws Exception {
      Key key = new SecretKeySpec(keyValue, ALGO);
      return key;
    }
  }
  </code></pre>
  
  <p>The JavaScript that I am trying to use to decrypt is </p>
  
  <pre><code>&lt;script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"&gt;   &lt;/script&gt;
  
  var decrypted = CryptoJS.AES.decrypt(encrypted,"Abcdefghijklmnop").toString(CryptoJS.enc.Utf8);
  </code></pre>
  
  <p>But the JavaScript decryption is not working. I am new to this, could someone tell me a way to solve without changing the Java code block ?</p>
  
  <p>I tried Base-64 decoding my text like this:</p>
  
  <pre><code>var words  = CryptoJS.enc.Base64.parse(encrKey);
  var base64 = CryptoJS.enc.Base64.stringify(words);
  var decrypted = CryptoJS.AES.decrypt(base64, "Abcdefghijklmnop");
  alert("dec :" +decrypted);
  </code></pre>
  
  <p>but still no good.</p>
  
  <p>I tried the solution suggested below to resolve possible padding issue but its not giving any solution.</p>
  
  <pre><code>var key = CryptoJS.enc.Base64.parse("QWJjZGVmZ2hpamtsbW5vcA==");
  var decrypt = CryptoJS.AES.decrypt( encrKey, key, { mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7 } );
  
  alert("dec :" +decrypt);
  </code></pre>