Skip to content

Instantly share code, notes, and snippets.

@stephenajulu
Forked from SymbianSyMoh/encrypt_decrypt.js
Created March 10, 2020 07:41
Show Gist options
  • Save stephenajulu/2f0cdedd0d4d38e6888b8e0894b08554 to your computer and use it in GitHub Desktop.
Save stephenajulu/2f0cdedd0d4d38e6888b8e0894b08554 to your computer and use it in GitHub Desktop.
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
var hw = encrypt("hello world")
decrypt(hw)
// feel free to change >> d6F3Efeq
// To test just copy + paste the above inside the node shell
// TIP: always encrypt IDs before sending via HTTP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment