1.字符串加密解密
//对普通的字符串 进行base64
var encryptionStr = new Buffer('123456').toString('base64');
console.log(encryptionStr ); // MTIzNDU2
//解码base64
var decryptStr = new Buffer('MTIzNDU2', 'base64').toString('utf8')
console.log(decryptStr ); // 123456
2.图片加密解密
//对图片的base64
var fs = require('fs');
//图片转换成base64
function base64_encode(file) {
var bitmap = fs.readFileSync(file);
return new Buffer(bitmap).toString('base64');
}
//base64转换成图片
function base64_decode(base64str, file) {
var bitmap = new Buffer(base64str, 'base64');
fs.writeFileSync(file, bitmap);
}
var base64str = base64_encode('a.png');//得到base64
base64_decode(base64str, 'a.copy.png');