title: How can I do Base64 encoding in Node.js?
body: <p>Does Node.js have built-in Base64 encoding yet?</p>
  <p>The reason why I ask this is that <code>final()</code> from <code>crypto</code> can only output hexadecimal, binary or ASCII data. For example:</p>
  <pre><code>var cipher = crypto.createCipheriv('des-ede3-cbc', encryption_key, iv);
  var ciph = cipher.update(plaintext, 'utf8', 'hex');
  ciph += cipher.final('hex');
  
  var decipher = crypto.createDecipheriv('des-ede3-cbc', encryption_key, iv);
  var txt = decipher.update(ciph, 'hex', 'utf8');
  txt += decipher.final('utf8');
  </code></pre>
  <p>According to the documentation, <code>update()</code> can output Base64-encoded data. However, <code>final()</code> doesn't support Base64. I tried and it will break.</p>
  <p>If I do this:</p>
  <pre><code>var ciph = cipher.update(plaintext, 'utf8', 'base64');
      ciph += cipher.final('hex');
  </code></pre>
  <p>Then what should I use for decryption? Hexadecimal or Base64?</p>
  <p>Therefore, I'm looking for a function to Base64-encode my encrypted hexadecimal output.</p>