title: CryptoJS decryption with counter
body: <p>I have following python code for AES decryption using <a href="https://pycryptodome.readthedocs.io/en/latest/src/cipher/aes.html" rel="nofollow noreferrer">pycryptodome</a>,  and which I verified and working.</p>
  
  <pre class="lang-py prettyprint-override"><code>key = "password"
  key = hashlib.sha256(key.encode("utf-8")).digest()
  iv = b'This is an IV456' #Random.new().read(AES.block_size)
  iv_int = int(binascii.hexlify(iv), 16)  # Convert the IV to a Python integer. 
  ctr = Counter.new(AES.block_size * 8, initial_value=iv_int) # Create a new Counter object with IV = iv_int.
  aes = AES.new(key, AES.MODE_CTR, counter=ctr)
  decryptData = aes.decrypt(encryptedData) # Decrypt and return the plaintext.
  </code></pre>
  
  <p>Now I need to convert this code in python using <a href="https://www.npmjs.com/package/crypto-js" rel="nofollow noreferrer">CryptoJS</a>, I have done some coding but no idea how counter <code>ctr</code> generated.</p>
  
  <pre class="lang-js prettyprint-override"><code>var i8a = new Uint8Array(data);
  var password = "password";
  var key = CryptoJS.SHA256(password);  
  var input = CryptoJS.lib.WordArray.create(i8a);
  var output =CryptoJS.AES.decrypt(input, key, { mode: CryptoJS.mode.CTR});                                                                                                                                                                                                                                                                                    
  var str = output.toString(CryptoJS.enc.Base64);  
  </code></pre>
  
  <p>But the <code>str</code> is always none. </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Based on below comment I have added <code>iv</code> and noPadding option with config but still the decrypt return empty.</p>
  
  <pre><code>  var iv = "112197289293498629157884805399637669174";
    //iv = CryptoJS.enc.Base64.parse(iv); //enable this doesn't make any changes. 
    var output =CryptoJS.AES.decrypt(input, key,{ mode: CryptoJS.mode.CTR,iv:iv,padding: CryptoJS.pad.NoPadding});
  </code></pre>
  
  <p>Where I got the iv value from python side <code>iv_int</code>.</p>
  
  <p>And cannot remove the <code>counter</code> from python script where I am getting error like,
  <code>'counter' keyword parameter is required with CTR mode</code></p>
  
  <p><strong>Note:</strong> I am sending the encrypted data from python to js through webRTC data channel.</p>
  
  <p><strong>Edit2:</strong></p>
  
  <p>The encrypt code in python which I actually used in python,</p>
  
  <pre><code>  def encrypt(row):
          key = "password"
          key = hashlib.sha256(key.encode("utf-8")).digest()
          iv = b'This is an IV456' #Random.new().read(AES.block_size)
          iv_int = int(binascii.hexlify(iv), 16) 
  
          ctr = Counter.new(AES.block_size * 8, initial_value=iv_int)
          cipher = AES.new(self.key, AES.MODE_CTR,counter=ctr)
          return base64.b64encode(cipher.encrypt(raw))
  </code></pre>
  
  <p>Input data for encryption</p>
  
  <pre><code>fp = open(filepathFull, "rb")
  while (True) and not done_reading:
      data = fp.read(16384)
      encrypted = encrypt(data) 
      sendWebrtcDataChannel(encrypted)
  </code></pre>