node.js有内置的base64编码吗?
为什么我问这个的原因是,final()从crypto只能输出十六进制,二进制或ASCII数据.例如:
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');
Run Code Online (Sandbox Code Playgroud)
根据文档,update()可以输出base64编码的数据.但是,final()不支持base64.我试过了,它会破裂.
如果我这样做:
var ciph = cipher.update(plaintext, 'utf8', 'base64');
ciph += cipher.final('hex');
Run Code Online (Sandbox Code Playgroud)
然后我应该用什么解密?Hex或base64?
因此,我正在寻找一个函数来对我的加密十六进制输出进行base64编码.
谢谢.