Node.js crypto-js AES encrypt/decrypt

Description

Node.js crypto-js AES encrypt/decrypt

var crypto = require('crypto-js');

var secretMessage = {
  name: 'Andrew',
  secretName: '007'
};
var secretKey = '123abc';

// Encrypt//from   w ww  .j  a  va 2  s  .c o m
var encryptedMessage = crypto.AES.encrypt(JSON.stringify(secretMessage), secretKey);
console.log('Encrypted Message: ' + encryptedMessage);

// Decrypt Message
var bytes = crypto.AES.decrypt(encryptedMessage, secretKey);
var decryptedMessage = JSON.parse(bytes.toString(crypto.enc.Utf8));

console.log(decryptedMessage);
console.log(decryptedMessage.secretName);



PreviousNext

Related