node crypto decipher data

来源:互联网 发布:win10 uefi 安装Ubuntu 编辑:程序博客网 时间:2024/06/05 16:36
var fs = require('fs');
var crypto = require('crypto');

var keyPem = fs.readFileSync('./key.pem');
// var certPem = fs.readFileSync('./cert.pem');
var publicKey = keyPem.toString('ascii');
// var certKey = certPem.toString();

var data = "hahahahahaahahahhahahhhahahahahaa";
console.log('befor sign: ' + data);

var cipher = crypto.createCipher('blowfish',publicKey);
var ciphered = cipher.update(data,'binary','hex');
ciphered += cipher.final('hex');

console.log(data.length);
console.log('after ciphered:' + ciphered);

var decipher = crypto.createDecipher('blowfish',publicKey);
var deciphered = decipher.update(ciphered,'hex','utf8');
deciphered += decipher.final('utf8');

console.log('after deciphered: ' + deciphered);
原创粉丝点击