您可以使用crypto模块:
var crypto = require('crypto');var assert = require('assert');var algorithm = 'aes256'; // or any other algorithm supported by OpenSSLvar key = 'password';var text = 'I love kittens';var cipher = crypto.createCipher(algorithm, key); var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex');var decipher = crypto.createDecipher(algorithm, key);var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');assert.equal(decrypted, text);编辑
现在 createCipher 和 createDecipher 已被弃用,而不是使用 createCipheriv 和
createDecipheriv



