Last active
August 24, 2020 10:20
-
-
Save roshnet/d352f10ba1020647989653707a6b908b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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