Improving the efficiency of AES decryption in Node.js

I had the idea to build a webpage that would display decrypted data fetched from the server. The app.js file on the server reads and decrypts all the data from a specific folder.

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');
};

The decrypted data is then sent to the webpage.

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");
      };

  });

However, the decryption process can take up to 30 seconds due to the large number of files (around 35 files, each approximately 5mb). I am aware that Node.js is single-threaded and lacks concurrency. So, I'm considering using Java or Python instead, as they support multi-threading and concurrency, which could potentially speed up the decryption process.

Answer №1

Crypto-JS offers a comprehensive JavaScript implementation of AES encryption. This versatile library can run smoothly in both browsers and NodeJs environments.

For applications solely on NodeJs, it is recommended to utilize the native crypto API for enhanced performance due to its inherent speed advantages.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The issue with style.background not functioning in Internet Explorer is causing complications

I am currently developing a JavaScript game that involves flipping cards. However, I have encountered an issue with the style.background property. It seems to be functioning correctly in Chrome but not in Internet Explorer. Here is the problematic code sn ...

Using Next-Image Relative Paths can lead to 404 errors when being indexed by web crawlers

I have implemented next-image in my project, and all the images are hosted on Cloudinary. The images display correctly, but when I run a website analysis using tools like Screaming Frog, I receive numerous 404 errors. This is because the tools are looking ...

The request for data:image/png;base64,{{image}} could not be processed due to an invalid URL

I am facing an issue with converting image data that I receive from the server using Angular.js for use in ionic-framework. Here is the code snippet I have been working with: $http.post(link, { token: token, reservationCode: reservatio ...

Converting CSV data into JSON format using NodeJs and integrating it with MongoDB

Here is how my CSV file is structured: "Some Comment here" <Blank Cell> Header1 Header2 Header3 Value1 Value2 Header4 Value3 Value4 I am looking to convert this into JSON format and store it in MongoDB as follows: Obj: { Key1: Header ...

EmeraldSocks Tweenmax motion design

I need help with Tweenmax animation. I'm attempting to animate an id selector, but nothing is happening. Both the selector and content are unresponsive. Can someone assist me? Here is the code: <!DOCTYPE html> <html> <head> ...

I am interested in incorporating the ability to select and scroll the window without needing to interact with the scroll bar by

Imagine a visitor wanting to highlight all the information on a webpage. They choose to start dragging their cursor towards the bottom of the window. How can we enable the webpage to smoothly scroll down as they do this? ...

Exploring the capabilities of the Angular 2 expression parser alongside the functionality of the

Is there a way to create an equivalent of the Angular 1.x ngInit directive in Angular 2? I am familiar with the ngOnInit hook, which is recommended for initialization code. The ngInit directive seems like a quick and declarative way to prototype or fix a ...

converting a JSON object into an array

I'm facing a challenge and unsure how to proceed. I have received JSON data from an API: https://i.stack.imgur.com/GdDUo.png When I log the data, this is what appears in the console: https://i.stack.imgur.com/GjSPW.png My goal is to extract the id ...

Anomaly in the default checked state of checkboxes

I'm currently working on a project and encountering an issue with the code below. I need to incorporate a forEach() loop within getElements() instead of using map(). Additionally, I want the default state of a checkbox to remain checked even after nav ...

Using Ajax and jQuery to dynamically insert an option into a datalist

I'm in the process of building a search box using Flask, MySQL, and ajax. I've managed to retrieve the search results in JSON format within the console, but now I want to dynamically add them to the options in my datalist element in the HTML. He ...

Setting a Favicon in KrakenJS - Step by Step Guide

I have thoroughly investigated the problem mentioned in this particular issue, but unfortunately, I haven't found a solution yet. Even utilizing app.use(express.favicon('/path/to/icon/')) does not appear to be effective in resolving the iss ...

Retrieve a dynamic file using a GET request at regular intervals

Hey, I've got this section in my app.js file. const app = require('express'); const fs = require('fs'); const Index = require('./routes/index'); const getData = require('./db/data').getData; const app=express() ...

Oh no! An error has occurred with the Express app: It seems that headers cannot be set after they

In my current project, I am developing an Express API application that includes roles within the system. To manage these roles, there is a "Disable" option available for each role. When a role is disabled, there is an API endpoint specifically designed to ...

import all mongoose models in the express app.js

Every time I create a model in my express app's app.js, I find myself having to include the model by writing out the specific path. require('./models/Users') require('./models/Projects') Is there a shortcut or more streamlined wa ...

Obtaining serverTime from a webpageWould you like to learn

Is it possible to retrieve the serverTime using jquery ajax functions like $.get() or $.post()? I am looking to store this serverTime in a variable that can be utilized later on in javascript. You can access the webpage at: To use the get and post functi ...

Heroku local is designed to support only NodeJS applications, without any Angular framework or database connectivity

I'm currently facing two separate issues. When I run my app locally, it works fine, but it doesn't function properly on Heroku. Running "heroku local" opens the NodeJS app on localhost:5000 and connects to the local database. However, when attemp ...

Implementing a play and pause button functionality for the carousel in Bootstrap 5

How can I implement a play/pause feature on the same button when clicking in a Bootstrap 5 carousel using jQuery? **HTML ** <div id="customSlider" class="carousel slide" data-bs-ride="carousel" data-bs-interval="2500& ...

Sending an array of objects to a MySQL database using React and NodeJS: A comprehensive guide

As someone who is new to NodeJS and Mysql databases, I am currently working on a small React project that involves a week calendar for booking lessons. My main focus right now is creating an admin panel where teachers can set their availability throughout ...

How to retrieve distinct items from an array using Javascript

If I have the following array of objects: const arr = [{ id: 'A', version: 0, name: 'first' }, { id: 'A', version: 1, name: 'first' }, { id: 'B', version: 0, name: 'second&apo ...

Customize a web template using HTML5, JavaScript, and jQuery, then download it to your local device

I am currently working on developing a website that allows clients to set up certain settings, which can then be written to a file within my project's filesystem rather than their own. This file will then have some parts overwritten and must be saved ...