Last active
December 21, 2022 15:24
-
-
Save siwalikm/9832f795e0317523c51b88151b123846 to your computer and use it in GitHub Desktop.
Encryption and decryption with Nodejs crypto
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'), | |
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