title: How to encrypt data in browser with JavaScript and decrypt on server side with Node.js
body: <p>I'm trying to encrypt a message using AES256 on the browser, send it to the server, and then decrypt it but I keep getting this error server-side :</p>
  
  <p><code>error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt</code></p>
  
  <p>I tried for hours to find a solution but I don't see where is the issue. I'm using <a href="https://github.com/brix/crypto-js" rel="nofollow noreferrer">crypto-js</a> for client-side and the standard library for Node.js <code>crypto</code></p>
  
  <p>This is the code sample that I'm using on client-side.</p>
  
  <pre><code>import * as CryptoJS from 'crypto-js';
  
  const secret = 'example';
  const passphrase = 'secret-passphrase'
  
  const encrypted = CryptoJS.AES.encrypt(secret, passphrase);
  const encrypted64 = CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
  
  // make a request to a Node.js API with the password encrypted
  </code></pre>
  
  <p>This is the code sample that I'm using on server-side.</p>
  
  <pre><code>const crypto = require('crypto');
  
  const secret = req.body.secret;
  
  const passphrase = 'secret-passphrase'
  const decipher = crypto.createDecipher('aes256', passphrase);
  
  let decrypted = decipher.update(secret, 'base64', 'utf8');
  decrypted += decipher.final('utf8');
  </code></pre>
  
  <p>Any idea?</p>
  
  <p>Thanks.</p>