title: AES encryption in java and decryption in javascript using CryptoJS
body: <p>I have below code to encrypt some file content in java by using AES/CTR/NOPADDING mode. I am using crypto package of javax. Also I am using same secret key to generate key and iv.</p>
  
  <pre><code>Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
  
          byte[] secretKey = Base64.decodeBase64("uQsaW+WMUrjcsq1HMf+2JQ==");
  
          SecretKeySpec key = new SecretKeySpec(secretKey, "AES");
          IvParameterSpec iv = new IvParameterSpec(secretKey);
  
          cipher.init(mode, key , iv);
  
          FileInputStream fileInputStream = new FileInputStream(sourceFilePath);
          FileOutputStream fileOutputStream = new FileOutputStream(destFilePath);
  
          int read = 0;
          while ((fileInputStream.available()) &gt; 0) {
              byte[] block = new byte[4096];
              read = fileInputStream.read(block);
              byte[] writeBuffer = cipher.update(block);
              fileOutputStream.write(writeBuffer, 0, read);
          }
  
          byte[] writeBuffer = cipher.doFinal();
          fileOutputStream.write(writeBuffer, 0, writeBuffer.length);
  
          fileInputStream.close();
          fileOutputStream.close();
  </code></pre>
  
  <p>I am not able to decrypt encrypted content in javascript by using cryptojs.
  Here is something I have tried.</p>
  
  <pre><code>var key = CryptoJS.enc.Hex.parse(atob('uQsaW+WMUrjcsq1HMf+2JQ=='));
  
  var decrypted = CryptoJS.AES.decrypt(encryptedContent, key, {
      mode: CryptoJS.mode.CTR,
      iv: key,
      padding: CryptoJS.pad.NoPadding
  });
  
  var decryptedText = CryptoJS.enc.Utf8.stringify(decrypted);
  </code></pre>
  
  <p>Can somebody tell me what I am doing wrong? Or tell me how to do it.</p>
  
  <p>I am able to encrypt and decrypt in java and javascript independently.</p>