Created
July 19, 2012 09:11
-
-
Save eliOcs/3142385 to your computer and use it in GitHub Desktop.
Cipher plain text with Node.js
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"); // native module that allows ciphering | |
var CIPHER_KEY = "test-key", CIPHER_ALGORITHM = "aes256"; | |
// Original message | |
var message = "This message will be ciphered"; | |
console.log("Original message -> " + message); | |
// Cipher message | |
var cipher = crypto.createCipher(CIPHER_ALGORITHM, CIPHER_KEY); | |
var cipheredMessage = cipher.update(message, "binary", "hex"); | |
cipheredMessage += cipher.final("hex"); | |
console.log("Ciphered message -> " + cipheredMessage); | |
// Decipher message | |
var decipher = crypto.createDecipher(CIPHER_ALGORITHM, CIPHER_KEY); | |
var decipheredMessage = decipher.update(cipheredMessage, "hex", "binary"); | |
decipheredMessage += decipher.final("binary"); | |
console.log("Deciphered message -> " + decipheredMessage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment