Skip to content

Instantly share code, notes, and snippets.

@siwalikm
Last active December 21, 2022 15:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save siwalikm/9832f795e0317523c51b88151b123846 to your computer and use it in GitHub Desktop.
Save siwalikm/9832f795e0317523c51b88151b123846 to your computer and use it in GitHub Desktop.
Encryption and decryption with Nodejs crypto
var crypto = require('crypto'),
algo = 'aes-256-cbc',
key = 'super123secretKey!';
function encrypt(text){
var cipher = crypto.createCipher(algo,key)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher(algo,key)
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
// var test = encrypt(`Trusure chest at 12.9695309 80.2415712`)
// "77de8c88c47701ab31c93e5f5f8379084797d6a11dde6097c7c5cce43224d85bbae53474f743eaccf5a806f2986a0970"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment