encrypt-decrypt-crypto

1.0.0 • Public • Published

encrypt-decrypt-crypto

The encrypt-decrypt-crypto package can be used to create a secret key, encrypt a plain text password and thereby generate an encrypted password and an IV, decrypt a password to plain text from the encrypted password and IV.

Installation

npm install encrypt-decrypt-crypto

Features

The package supports the below features:

  • Create a base64-encoded encryption key
  • Encrypt a plain text password to an encrypted password and an IV using a Secret key (initialization vector - An initialization vector (IV) is an arbitrary number that can be used with a secret key for data encryption to foil cyber attacks. This number, also called a nonce (number used once), is employed only one time in any session to prevent unauthorized decryption of the message by a suspicious or malicious actor.)
  • Decrypt an encrypted password using the corresponding key and IV.

Usage

  1. Install the package.

  2. To Create a Secret key a. Create a new file to create the secret key b. Import the current package const credentialHelper = require('encrypt-decrypt-crypto'); c. Add a call to create a secret key - mostly used one time or when the secret key needs to be changed const secretKey = await credentialHelper.createSecretKey(); console.log("Secret Key: " + secretKey); d. Run the file to create the Secret key, sample command below node script.js

  3. Encrypt a plain text password a. Create a new file for encryption OR reuse the above file created for secret key b. Import the current package const credentialHelper = require('encrypt-decrypt-crypto'); c. Add a call to encrypt the password - mostly used one time or when the plain text password is changed. The return value is an array where the first value is the Encrypted text and the second value is the IV. const encryptedText = await credentialHelper.encryptText("plainTextPassword", secretKey); console.log("Encrypted Text is: " + encryptedText[0] + ", IV: " + encryptedText[1]); d. Run the file to encrypt the Plain text password, sample command below: node script.js

  4. Decrypted the encrypted password a. Import the current package in the file where the decryption of the password is needed. const credentialHelper = require('encrypt-decrypt-crypto'); b. Add a call to decrypt the password and pass the encrypted text, IV and the secret key. const decryptedText = await credentialHelper.decryptText(encryptedText, IV, secretKey); console.log("Decrypted Plain password: " + decryptedText);

Note: The createSecretKey, encryptText and decryptText are async functions, so please add the calls to these in an async function or an async block. Sample below: (async () => { ---- code here })();

Readme

Keywords

Package Sidebar

Install

npm i encrypt-decrypt-crypto

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

4.63 kB

Total Files

3

Last publish

Collaborators

  • sreejit.s139