npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

encryption-decryption-easy

v1.0.8

Published

This package is used to encrypt-decrypt keys of an Object, array of object and normal string

Downloads

548

Readme

Encryption-Decryption Library for Object , Array of Object,Key and String

encryption-decryption is a Node.js library that provides easy-to-use functions for encrypting and decrypting specific keys within objects, arrays, and strings. The library supports both CommonJS and ES6 module formats.

Features

  • Encrypt and decrypt specific keys within an object or array.
  • Supports string encryption and decryption.
  • Simple API with easy integration into existing Node.js projects.

Installation

To install the package, use npm:

npm install encryption-decryption-easy

Usage

You can use this library with both ES6 modules and CommonJS.

ES6 Module Example

import {EncryptionLibrary} from 'encryption-decryption-easy';

// ENV keys = SECRET_KEY, IV, SALT

const instance = new EncryptionLibrary()

// Encrypt object keys
const inputObject = { name: 'John Doe', ssn: '123-45-6789' };
const encryptedObject = instance.encryptObjectKeys(inputObject, ['ssn']);
console.log('Encrypted Object:', encryptedObject);

// Decrypt object keys
const decryptedObject = instance.decryptObjectKeys(encryptedObject, ['ssn']);
console.log('Decrypted Object:', decryptedObject);


// Encrypt Array of object keys
const inputArrayOfObject = [{ name: 'John Doe', ssn: '123-45-6789' }];
const encryptedArrayOfObject = instance.encryptObjectKeys(inputArrayOfObject, ['ssn']);
console.log('Encrypted Object:', encryptedArrayOfObject);

// Decrypt Array of object keys
const decryptedArrayOfObject = instance.decryptObjectKeys(encryptedArrayOfObject, ['ssn']);
console.log('Decrypted Object:', decryptedArrayOfObject);

// Encrypt String

const inputString = "myPassword"
const encryptedPassword = instance.encryptObjectKeys(inputString, ['inputString'])

console.log('Encrypted string:', encryptedPassword);


const decryptedPassword = instance.encryptObjectKeys(encryptedPassword, ['encryptedPassword'])

console.log('Decrypted string:', decryptedPassword);

CommonJS Module Example

import {EncryptionLibrary}  = require('encryption-decryption-easy');

// ENV keys = SECRET_KEY,  IV, SALT

const instance = new EncryptionLibrary()

// Encrypt object keys
const inputObject = { name: 'John Doe', ssn: '123-45-6789' };
const encryptedObject = instance.encryptObjectKeys(inputObject, ['ssn']);
console.log('Encrypted Object:', encryptedObject);

// Decrypt object keys
const decryptedObject = instance.decryptObjectKeys(encryptedObject, ['ssn']);
console.log('Decrypted Object:', decryptedObject);


// Encrypt Array of object keys
const inputArrayOfObject = [{ name: 'John Doe', ssn: '123-45-6789' }];
const encryptedArrayOfObject = instance.encryptObjectKeys(inputArrayOfObject, ['ssn']);
console.log('Encrypted Object:', encryptedArrayOfObject);

// Decrypt Array of object keys
const decryptedArrayOfObject = instance.decryptObjectKeys(encryptedArrayOfObject, ['ssn']);
console.log('Decrypted Object:', decryptedArrayOfObject);

// Encrypt String

const inputString = "myPassword"
const encryptedPassword = instance.encryptObjectKeys(inputString, ['inputString'])

console.log('Encrypted string:', encryptedPassword);


const decryptedPassword = instance.encryptObjectKeys(encryptedPassword, ['encryptedPassword'])

console.log('Decrypted string:', decryptedPassword);

CLASS Method

encryptObjectKeys(input, keys)

Encrypts the specified keys in the given input object, array, or string.

  • input: The object, array, or string to be encrypted.
  • keys: An array of keys to encrypt within the object or array.

Example:

const encryptedObject = instance.encryptObjectKeys({ ssn: '123-45-6789' }, ['ssn']);

decryptObjectKeys(input, keys)

Decrypts the specified keys in the given input object, array, or string.

  • input: The object, array, or string to be decrypted.
  • keys: An array of keys to decrypt within the object or array.

Example:

const decryptedObject = instance.decryptObjectKeys(encryptedObject, ['ssn']);

Environment Variables

For enhanced security, you can configure the following environment variables:

| Variable | Description | Default Value | |-----------------|-----------------------------------------------------|--------------------------------------------------| | SECRET_KEY | The secret key used for encryption and decryption. | 'some random string of 32 characters' | |-----------------|------------------------------------------------------|--------------------|
| SALT | A salt string added for additional security during encryption. | 'some random string of 64 characters' |

Example

To set these environment variables in your .env file:

SECRET_KEY=your-32-character-secret-key
SALT=your-64-character-salt-string

### Security Considerations

- Ensure that your **secretKey** and **itetrations** values remain consistent between encryption and decryption.
- Store secret keys and itetrations  securely using environment variables or secure key management systems.
- Strong encryption algorithms (e.g., AES-256-CBC) are recommended for sensitive data.

## License

This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.