Does node.js have built-in base64 encoding yet?
The reason why I ask this is that final()
from crypto
can only output hex, binary or ascii data. For example:
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');
According to the docs, update()
can output base64-encoded data. However, final()
doesn't support base64. I tried and it will break.
If I do this:
var ciph = cipher.update(plaintext, 'utf8', 'base64');
ciph += cipher.final('hex');
Then what should I use for decryption? Hex or base64?
Therefore, I'm looking for a function to base64-encode my encrypted hex output.
cipher.final('base64')
works – avck