Created
May 28, 2014 10:08
-
-
Save GuillermoPena/e516d762c3d0d3f758a4 to your computer and use it in GitHub Desktop.
NodeJS - CRYPTO : Symetric Cryptography of Strings
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') | |
// 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