node crypto decipher data
闻鹤龄
2023-12-01
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);