Does node.js have built-in base64 encoding yet? (node.js有内置的base64编码吗?)
The reason why I ask this is that final()
from crypto
can only output hex, binary or ascii data. (我之所以这么说是因为来自crypto
final()
只能输出hex,binary或ascii数据。) 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. (根据文档, update()
可以输出base64编码的数据。) However, final()
doesn't support base64. (但是, final()
不支持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? (Hex或base64?)
Therefore, I'm looking for a function to base64-encode my encrypted hex output. (因此,我正在寻找一个函数来对我的加密十六进制输出进行base64编码。)
Thanks. (谢谢。)
ask by murvinlai translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…