How to use the crypto module by Josh Holbrook jesusabdullah on Friday, Aug 26 2011 https://docs.nodejitsu.com/articles/cryptography/how-to-use-crypto-module/
https://nodejs.org/api/crypto.html
require("crypto")
.createHash("md5")
.update("Man oh man do I love node!")
.digest("hex");
require("crypto").createHmac("md5", "password")
.update("If you love node so much why don't you marry it?")
.digest("hex");
#!/usr/bin/env node
var crypto = require("crypto"),
argv = require("optimist").argv;
if (argv.e && argv.password) {
var cipher = crypto.createCipher("aes192", argv.password),
msg = [];
argv._.forEach( function (phrase) {
msg.push(cipher.update(phrase, "binary", "hex"));
});
msg.push(cipher.final("hex"));
console.log(msg.join(""));
} else if (argv.d && argv.password) {
var decipher = crypto.createDecipher("aes192", argv.password),
msg = [];
argv._.forEach( function (phrase) {
msg.push(decipher.update(phrase, "hex", "binary"));
});
msg.push(decipher.final("binary"));
console.log(msg.join(""));
}
./secretmsg.js -e --password="popcorn" "My treasure is buried behind Carl's Jr. on Telegraph."
6df66752b24f0886f8a6c55e56977788c2090bb657ff3bd645097f8abe11099963fb3bd9627986c60fa7e5120d8fead928cff620b37e3e79be8de519f490527a
Now, if I gave somebody the same script, my encoded message and the password, they can decode the message and find out where I buried my treasure:
./secretmsg.js -d --password="popcorn" 6df66752b24f0886f8a6c55e56977788c2090bb657ff3bd645097f8abe11099963fb3bd9627986c60fa7e5120d8fead928cff620b37e3e79be8de519f490527a
My treasure is buried behind Carl's Jr. on Telegraph.