Created
December 8, 2017 20:39
-
-
Save seangeleno/da0ebc929e670445dde35e0e542aa069 to your computer and use it in GitHub Desktop.
nodejs crypto cipher example
This file contains 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'); | |
var plainText = '8a30e4ee9a592acdce626d0f3caccd020deb9b1fa1d5996bbf8908860ea5aa68'; | |
var chooseCipher = crypto.getCiphers(); | |
try | |
{ | |
var cipher = crypto.createCipher(chooseCipher[32], 'password'); | |
var cipherText2 = Buffer.concat([cipher.update(new Buffer(plainText)), cipher.final()]); | |
console.log('Method 2 - plainText:' + plainText + '\n'); | |
console.log('Method 2 - cipherText length:' + cipherText2.length + '\n'); | |
console.log('Method 2 - cipher:' + cipherText2 + '\n'); | |
var decipher = crypto.createDecipher(chooseCipher[32], 'password'); | |
var result2 = decipher.update(cipherText2); | |
result2 += decipher.final(); | |
console.log('Method 2 - result:' + result2 + '\n'); | |
} | |
catch (err) | |
{ | |
console.log(err.message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment