New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

secure-crypto-node-utils

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

secure-crypto-node-utils

A collection of essential cryptographic utilities for secure communication in Node.js application. Includes methods for encryption and decryption using AES-256-CBC algorithm with customizable secret keys.

1.0.19
unpublished
latest
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Secure Crypto Node Utils

Node Secure Crypto Utils is a comprehensive library providing essential cryptographic utilities for secure communication in Node.js applications. It includes methods for encryption and decryption using the AES-256-CBC algorithm with customizable secret keys, ensuring robust security for your data transmission needs.

Features

  • Encryption: Encrypt sensitive data using the AES-256-CBC algorithm.
  • Decryption: Safely decrypt encrypted data using secure cryptographic methods.
  • Customizable Secret Keys: Customize secret keys to tailor the security level to your specific requirements.
  • Error Handling: Robust error handling ensures secure data transmission even in challenging conditions.

Installation

To install Node Secure Crypto Utils, you can use npm:

npm install node-secure-crypto-utils

Usage

Node Secure Crypto Utils is primarily used to encrypt and decrypt data transmitted between a client and a Node.js server. Here's how you can use it:

1. Create .env file

 Create a .env file to provide the encryption keys in your root directory. The folder structure should be as follows:
    |---root
     |---bin
     |   |-- .env

   In the .env file, provide the encryption keys:
    .env
    AES_ENC_SECRET_KEY=your-secret-key
    AES_ENC_IV=your-IV-key

Note:

  • For obtaining the encryption keys, please contact hbabu@compindia.com.
  • For suggestions, feedback, or requests, please feel free to reach out to us via email at hbabu@compindia.com. We value your input and strive to implement your suggestions.

2. Encryption:

const { encrypt } = require('secure-crypto-node-utils');

// Encrypt sensitive data
const encryptedData = encrypt('Hello World');

2. Decryption:

const { decrypt } = require('secure-crypto-node-utils');
// Decrypt encrypted data
const decryptedData = decrypt(encryptedData);

EXAMPLE

To enable encryption and decryption for request and response handling, follow these steps:

1. Decrypting Request Data:

To decrypt incoming request data, utilize middleware in your routes file. For example my folder structure is organized as follows:


    |---root
      |---bin
      |   |-- .env
      |---middlewares
      |   |-- default.mw.js
      |---routes.js

In your routes.js file, require and use the decryption middleware:


    var defaultMiddleware  = require("middlewares/default.mw.js");
    router.use(defaultMiddleware.DecryptHandler);
    // declare your API endpoint below

And in your default.mw.js middleware file:


    middlewareObj.DecryptHandler = async function (req, res, next) {
        // if you need to omit encryption you can use like below
        if (req.path == '/test' || req.path == '/test2') {
            req.is_no_enc = true;
        }else{
            // Decrypt encrypted data
            req.body = await decrypt(req.body.data);
        }

        next();
    }

2. Encrypting Response Data:

To encrypt the response data before sending it to the client, set up a function like below and call it within your API route handler while preparing the response. Ensure to use your encryption methods provided by secure-crypto-node-utils.


   async function sendResponse(req, res, response) {
        // you can add your conditions to process response
        response = { data: await encrypt(response) };
        res.json(response);
   }

Keywords

encryption

FAQs

Package last updated on 07 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts