1.0.6 • Published 2 months ago

rsa-crypto-node v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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.

1.0.6

2 months ago

1.0.5

2 months ago

1.0.4

2 months ago