Saviollage / encrypt-decrypt-node

Override readFile() and writeFile() to encrypt/decrypt data using only nodeJs native modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Securing Files using NodeJs

The purpose of this project is to override the readFile() and writeFile() methods from within the module. So, whenever any method uses writeFile() to save a file, we will intercept this function, encrypt the data and let the stream continue saving the file.

To get the readable content from these files, we will intercept the readFile() call. After it gets the encrypted content from the file, we will call the function to do the reverse process, decrypting and returning the readable data to the caller.

Project developed based on the video "How to intercept native Node.js functions to encrypt data" on Erick Wendel's youtube channel

πŸ“ƒ Example

Content

const filetarget = "super-secret-file.txt.enc";
const data = "Agora: 2021-04-09T19:30:35.967Z";
await promises.writeFile(filetarget, text);

super-secret-file.txt.enc

dOM04WsOfu8enHGAdkmF6KYc+TGZo2I3HqqTDHvHf8s=

πŸš€ Instalation

  # Clone the project:
  $ git clone https://github.com/saviollage/encrypt-decrypt-node

    # Enter Directory:
  $ cd encrypt-decrypt-node

  # Install the dependencies:
  $ npm ci

  # Running app:
  $ npm start

About

Override readFile() and writeFile() to encrypt/decrypt data using only nodeJs native modules


Languages

Language:JavaScript 100.0%