使用Node.js进行加密和解密

加密和解密

var crypto = require('crypto');
var algorithm = 'aes-256-ctr';
var passphrase = "7IeZlmfz";

var encrypt = (text) => {
  var cipher = crypto.createCipher(algorithm,passphrase)
  var crypted = cipher.update(text,'utf8','base64')
  crypted += cipher.final('base64');
  return crypted;
}

var decrypt = (text) => {
  var decipher = crypto.createDecipher(algorithm,passphrase)
  var dec = decipher.update(text,'base64','utf8')
  dec += decipher.final('utf8');
  return dec;
}

确认

console.log(encrypt("こんにちは"));
console.log(decrypt(encrypt("こんにちは")));

请参考

广告
将在 10 秒后关闭
bannerAds