1.0.9 • Published 10 months ago

encryption-decryption-easy v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

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:

VariableDescriptionDefault Value
SECRET_KEYThe secret key used for encryption and decryption.'some random string of 32 characters'
-------------------------------------------------------------------------------------------
SALTA 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.
1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago