Skip to content

Instantly share code, notes, and snippets.

@roshnet
Last active August 24, 2020 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roshnet/d352f10ba1020647989653707a6b908b to your computer and use it in GitHub Desktop.
Save roshnet/d352f10ba1020647989653707a6b908b to your computer and use it in GitHub Desktop.
var crypto = require("crypto");
var algorithm = "aes-192-cbc";
var password = "Store this password in a .env file!";
const key = crypto.scryptSync(password, 'salt', 24);
var text = "secret message";
const iv = crypto.randomBytes(16); // different each time
const cipher = crypto.createCipheriv(algorithm, key, iv);
var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex');
console.log(encrypted);
const decipher = crypto.createDecipheriv(algorithm, key, iv);
var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
console.log(decrypted);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment