Skip to content

Instantly share code, notes, and snippets.

@GoNode5
Last active February 14, 2016 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoNode5/769af0d0fd2309fff7ab to your computer and use it in GitHub Desktop.
Save GoNode5/769af0d0fd2309fff7ab to your computer and use it in GitHub Desktop.
nodejs encrypt files
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