title: decrypting CyproJS AES encryption in Cryptodome python
body: <p>I am trying to decrypt message (in python) that has been encoded using CryptoJS in JavaScript. I have created an API in python, to post data I am using postman pre-request script.</p>
  <p>The Error I am getting:</p>
  <blockquote>
  <p>ValueError: Data must be padded to 16 byte boundary in CBC mode</p>
  </blockquote>
  <p><strong>JavaScript code for encryption</strong></p>
  <pre><code>var data = {&quot;feature_0&quot;: 0,
              &quot;feature_1&quot;: 0, 
              &quot;feature_2&quot;: 0, 
              &quot;feature_3&quot;: 0, 
              &quot;feature_4&quot;: 0, 
              &quot;feature_5&quot;: 0
             };
  let password = &quot;lazydog&quot;;
  let salt = &quot;salt&quot;;
  let iterations = 128;
  data = JSON.stringify(data);
  let len = 16 - ((data.length) % 16);
  data += len.toString().repeat(len);  --&gt; removed (as suggested)
  let bytes = CryptoJS.PBKDF2(password, salt, { keySize: 48, iterations: iterations });
  let iv = CryptoJS.enc.Hex.parse(bytes.toString().slice(0, 32));
  let key = CryptoJS.enc.Hex.parse(bytes.toString().slice(32, 96));
  
  let encrypted = CryptoJS.AES.encrypt(data, key, {iv: iv}); //, mode: CryptoJS.mode.CBC
  //encrypted = btoa(encrypted); --&gt; removed (as suggested)
  encrypted = encrypted.toString() --&gt;added (as suggested)
  postman.setGlobalVariable(&quot;data&quot;, encrypted);
  </code></pre>
  <p><strong>python code for decryption:</strong></p>
  <pre><code>def decode(encrypted):
      data = b64decode(encrypted)  
      byte = PBKDF2(&quot;lazydog&quot;.encode(&quot;utf-8&quot;), &quot;salt&quot;.encode(&quot;utf-8&quot;), 48, 128)
      iv = byte[0:16]
      key = byte[16:48]
      cipher = AES.new(key, AES.MODE_CBC, iv)
      text = cipher.decrypt(data) ## error is at this line
      text = text[:-text[-1]].decode(&quot;utf-8&quot;)
  
      return text
  </code></pre>
  <p>As the error said padding problem I added padding in JS code. Still I am not getting good results.
  What's wrong I am doing here?</p>