Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GuillermoPena/e516d762c3d0d3f758a4 to your computer and use it in GitHub Desktop.
Save GuillermoPena/e516d762c3d0d3f758a4 to your computer and use it in GitHub Desktop.
NodeJS - CRYPTO : Symetric Cryptography of Strings
var crypto = require('crypto')
// Encrypt/Decrypt a string
var key = "SecretKey"
, message = "This is the text to cipher!"
// Encrypting
var cipher = crypto.createCipher('des-ede3-cbc', key)
, cryptedMessage = cipher.update(message, 'utf8', 'hex')
cryptedMessage+= cipher.final('hex')
// Decrypting
var decipher = crypto.createDecipher('des-ede3-cbc', key)
, decryptedMessage = decipher.update(cryptedMessage, 'hex', 'utf8')
decryptedMessage += decipher.final('utf8')
console.log("Crypted Text:", cryptedMessage)
console.log("Decrypted Text:", decryptedMessage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment