如何在node.js中进行Base64编码?

node.js Node.js

神奇飞云

2020-03-14

node.js是否具有内置的base64编码?

我之所以这样问,是因为final()from 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');

根据文档,update()可以输出base64编码的数据。但是,final()不支持base64。我尝试过,它会破裂。

如果我这样做:

var ciph = cipher.update(plaintext, 'utf8', 'base64');
    ciph += cipher.final('hex');

那我应该用什么解密呢?十六进制还是base64?

因此,我正在寻找一个函数来对加密的十六进制输出进行base64编码。

第1575篇《如何在node.js中进行Base64编码?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android