Skip to content

relativity-codes/rsa-crypto-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js RSA Encryption Module

This Node.js module provides functions for RSA encryption and decryption using public and private keys. It utilizes the crypto module for cryptographic operations and supports loading keys from environment variables or default paths.

Table of Contents

Installation

To use this module, make sure you have Node.js installed. Then, install the required dependencies:

npm install rsa-crypto-node

Configuration

  1. Create a .env file in the root of your project.

  2. Add the paths to your public and private key files as environment variables:

    PUBLIC_KEY_PATH=./keys/public_key.pem
    PRIVATE_KEY_PATH=./keys/private_key.pem

Usage

import rsaEncryption from 'rsa-crypto-node';

Encrypt with Public Key

const textToEncrypt = 'Hello, World!';
const encryptedText = rsaEncryption.encryptWithPublicKey(textToEncrypt);
console.log('Encrypted:', encryptedText);

Decrypt with Private Key

const encryptedText = '...'; // Replace with the actual encrypted text
const decryptedText = rsaEncryption.decryptWithPrivateKey(encryptedText);
console.log('Decrypted:', decryptedText);

Encrypt with Private Key (Non-Standard)

const textToEncrypt = 'Hello, World!';
const encryptedText = rsaEncryption.encryptWithPrivateKey(textToEncrypt);
console.log('Encrypted with Private Key:', encryptedText);

Decrypt with Public Key (Non-Standard)

const encryptedText = '...'; // Replace with the actual encrypted text
const decryptedText = rsaEncryption.decryptWithPublicKey(encryptedText);
console.log('Decrypted with Public Key:', decryptedText);

Note: The last two methods (encrypting with the private key and decrypting with the public key) are non-standard use cases and may have security implications. Please use them cautiously based on your specific requirements.

Testing

To run tests, make sure you have Mocha and Chai installed:

npm install mocha chai --save-dev

then run test

npm test

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published