2

I wanted to create web page on which would be displayed data, previously decrypted on server. On server in app.js all of data from one folder is read and then decrypted.

var http = require('http');
var path = require('path');
var express = require('express');
var fs = require('fs');
var app = express();
var CryptoJS = require("crypto-js");
app.set('view engine', 'ejs');

var bytes = [];

var markers = fs.readdirSync("views/images");

for (var i = 0; i < markers.length ; ++i) {
bytes[i] = fs.readFileSync("views/images/" + 
markers[i]).toString('utf8');
};

Than data is decrypted and send to page

app.get('/index', function(req, res) {
app.use(express.static(__dirname + '/views'));
try{
      for (var i = 0; i < markers.length ; ++i) {
      bytes[i] = CryptoJS.AES.decrypt(markers[i],Rf3hgf93).toString(CryptoJS.enc.Utf8);                       
       };
      res.render('index',{bytes:bytes});

      }catch (err){
         res.render('index',{bytes:''});
         console.log("error");
      };

  });

The thing is, it takes about 30 seconds to decrypt all of this files and send to client. There are about 35 decrypted txt files(each about 5mb). I know that node js is single-threaded and there is no concurrency. So, how can I speed up decrypting process ? Should I use Java/Python instead of node js, as far as I am concerned java is the most suitable language for this process because of multi-threading and concurrency.

Stageflix
  • 31
  • 4
  • if the files are the same and never change or change by adding new ones, then a caching mechanism can help. Then one can try to spawn another process to decrypt the files and communicate to the parent process eg via a file-lock mechanism My 2 cents – Nikos M. Nov 15 '18 at 19:36

1 Answers1

1

crypto-js is a pure JavaScript AES implementation. It is meant to run in a browser as well as in NodeJs.

For a pure NodeJs application use the built-in crypto API, which is native and as such much faster.

rustyx
  • 80,671
  • 25
  • 200
  • 267