var crypto = require('crypto');
var buf = crypto.randomBytes(32);
var randomstring = buf.toString('base64').substr(0, 8);
console.log(randomstring);
var crypto = require('crypto');
const secret = 'abcdefg';
const cipher = crypto.createCipher('aes-256-cbc', secret);
let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log(encrypted);
const decipher = crypto.createDecipher('aes-256-cbc', secret);
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log(decrypted);
const ciphers = crypto.getCiphers();
console.log(ciphers);
const hashes = crypto.getHashes();
console.log(hashes);
參考網站: