Last active
February 14, 2016 13:07
-
-
Save GoNode5/769af0d0fd2309fff7ab to your computer and use it in GitHub Desktop.
nodejs encrypt files
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 fs = require('fs'); | |
var crypto = require('crypto'); | |
var password = new Buffer('{cCQ3d^b&5/Wfp}MV%@Dhy;N)qvTu@?!h:eXL#;A?xS=wZb[w(Z>H^FyK%/P*3aB=_(~A%]f[)LjMVuH(s!Kw%fJwL'); | |
var items=['file1','file2','file3'] | |
for (var i=0;i<items.length;i++) { | |
var aes = crypto.createCipher('aes-256-ctr', password); | |
var stream = fs.createReadStream(items[i]); | |
console.log('start write') | |
var wstream = fs.createWriteStream(items[i]+'.aes'); | |
stream | |
.pipe(aes) // encrypts with aes256 | |
.pipe(wstream) // writes to myfile.encrypted | |
.on('finish', function (error) { // finished | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment