this.symmetricEncryptiv = function(data, key, iv, algorithm){ if (!iv) throw new Error('an iv is reuired for this operation'); if (!algorithm) algorithm = 'aes-256-ctr'; var cipher = crypto.createCipheriv(algorithm, key, iv); return cipher.update(data, 'utf8', 'hex') + cipher.final('hex'); };
document.getElementById('fileinput').addEventListener('change', function(){ //for(var i = 0; i<this.files.length; i++){ //var file = this.files[i]; var file = this.files[0]; var logStream = through(function(data) { console.log('logStream decrypted: ', data); this.queue(); }); //console.group("File "+i); console.group("File 1"); console.log("name : " + file.name); console.log("size : " + file.size); console.log("type : " + file.type); console.log("date : " + file.lastModified); console.groupEnd(); var reader = new FlipStream.Readable(file); // Init the cipher bits var cipher = crypto.createCipheriv('aes-128-cbc', sessionKey, iv); console.log('Creating fileReader stream from the file: %s', file.name); var stream = self.createStream({name: file.name, size: file.size}); console.log("Piping fileBuffer through cipher then stream"); reader.pipe(cipher).pipe(stream); reader.on('end', function() { console.log('Reader is done...'); }); var oldReaderEmit = reader.emit; // Lets us know what events are being emitted reader.emit = function() { var emitArgs = arguments; console.log('emitting: ', emitArgs); oldReaderEmit.apply(reader, arguments); }; }, false);