Skip to content

Instantly share code, notes, and snippets.

@bithavoc
Created October 20, 2011 02:17
Show Gist options
  • Save bithavoc/1300252 to your computer and use it in GitHub Desktop.
Save bithavoc/1300252 to your computer and use it in GitHub Desktop.
Asymmetric Encryption Sample in Node.js: Encrypt and Decrypt using Password as a key(SECRET_KEY) / Triple-DES
/*
Asymmetric Encryption Sample in Node.js: Encrypt and Decrypt using Password as a key(SECRET_KEY)
Algorithm: des-ede3-cbc (Three key Triple-DES EDE in CBC mode)
johan@firebase.co
@thepumpkin
*/
var assert = require('assert')
var crypto = require('crypto')
var Buffer = require('buffer').Buffer
var SECRET_KEY = "ChuckN0rrisL1kesPur3D3PapaSuperKey"
var ENCODING = 'hex'
var text = "This is the text to cipher!"
var cipher = crypto.createCipher('des-ede3-cbc', SECRET_KEY)
var cryptedPassword = cipher.update(text, 'utf8',ENCODING)
cryptedPassword+= cipher.final(ENCODING)
var decipher = crypto.createDecipher('des-ede3-cbc', SECRET_KEY)
var decryptedPassword = decipher.update(cryptedPassword, ENCODING,'utf8')
decryptedPassword += decipher.final('utf8')
assert.equal(text, decryptedPassword)
console.log("Crypted Text:", cryptedPassword)
console.log("Decrypted Text:", decryptedPassword)
@jokesterfr
Copy link

Hey, that's not asymmetric, but symmetric!
http://fr.wikipedia.org/wiki/Data_Encryption_Standard

@samyan
Copy link

samyan commented Jan 24, 2014

That's is symetric because asymetric has 2 secret keys, public and private.

@coolaj86
Copy link

@JamieMcNaught
Copy link

This is totally not asymmetric encryption.

@flowermlh
Copy link

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOT AAAAAAAAAAsymmetic!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment