title: Node Crypto Error - wrong final block length
body: <p>I am getting an error when decrypting a response using <code>crypto</code> that i don't understand <code>Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length</code></p>
  <p>I'm decrypting a response that looks like this <code>'p6\u001e�s�p&gt;l?a%ޟ�=~m�\u0002D�K(�[&lt;\u0007O�6\u001c�a�[sP�=\u00112\u001d�)n�Ⴓ?</code>, i've shortened it for brevity. The end result is that it should be a JSON object</p>
  <p>My code is as follows</p>
  <pre><code>  const crypto = require('crypto');
    const secret = &quot;mysecret&quot;;
    const algorithm = 'aes-128-cbc';
  
    function decryptAES(message) {
  
      const bytes = Buffer.from(message);
      const salt = bytes.slice(bytes.length - 8);
      const key = crypto.pbkdf2Sync(secret, salt, 10000, 16, 'sha1');
      const iv = bytes.slice(bytes.length - 24, bytes.length - 8);
      const data = bytes.slice(0, bytes.length - 24);
    
      const decipher = crypto.createDecipheriv(algorithm, key, iv);
      let decrpyted = decipher.update(data, 'hex', 'utf8');
      decrpyted = Buffer.concat([decrpyted, decipher.final('utf8')])
      console.log(decrpyted.toString());
    }
  </code></pre>
  <p>What could I be doing wrong and what does the error message mean?</p>
  <h2>Update</h2>
  <p>From looking at how the data is encrypted the other side I can see that they are using <code>PKCS7Padding</code>. In my decryption code I am not specifying this. Can this be done with <code>crypto</code>?</p>