2.0.5 • Published 12 months ago

crypto-driver v2.0.5

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

CryptoDriver

The CryptoDriver is a simple and easy-to-use encryption class, manages cipher and decipher of data using the Advanced Encryption Standard (AES) AES-256-GCM algorithm with a user-provided password. This algorithm uses a 256-bit key and is considered one of the most secure symmetric encryption algorithms available.

Table of Contents

Installation

You can install CryptoDriver via npm:

npm install crypto-driver

Importing

To use CryptoDriver in your JavaScript application, first import it:

// Using ES6 imports
import CryptoDriver from 'crypto-driver';

// Using Node.js `require()`
const CryptoDriver = require('crypto-driver');

Usage

The CryptoDriver module is a class that needs to be instantiated with a password before it can be used. Once instantiated, you can use the encrypt() and decrypt() methods to encrypt and decrypt data.

const CryptoDriver = require('crypto-driver');

const password = 'this is secret';
const crypto = new CryptoDriver(password);

const data = 'This is my secret message';

// Encrypt the original data
const encrypted = crypto.encrypt(data);

// Decrypt the encrypted data
const decrypted = crypto.decrypt(encrypted);

console.log(data); // This is my secret message
console.log(encrypted); // 2fV+Hd1vN6rByYjKsNixNl2eDvUJziG/6kKj8zJb+zk=BvLrZrTjTxbV6QAAAAA
console.log(decrypted ); // This is my secret message

API

CryptoDriver(password)

Creates an instance of the CryptoDriver class.

Arguments

NameTypeDescription
passwordstringThe password used for encryption and decryption. Must be a string of 32 characters.

Throws

TypeDescription
ReferenceErrorIf the password value is undefined.
TypeErrorIf the password value is not a string.

Example

const CryptoDriver = require('crypto-driver');

const password = 'this is secret';
const crypto = new CryptoDriver(password);

CryptoDriver#encrypt(data)

Encrypts the specified data using the AES-256-GCM encryption algorithm.

Arguments

NameTypeDescription
datastringThe data to be encrypted. Must be a string.

Returns

A string representing the encrypted data.

Throws

TypeDescription
ReferenceErrorIf the data value is undefined.
TypeErrorIf the data value is not a string.

Example

const encrypted = crypto.encrypt('This is my secret message');

CryptoDriver#decrypt(encrypted)

Decrypts the specified encrypted data using the AES-256-GCM encryption algorithm.

Arguments

NameTypeDescription
encryptedstringThe encrypted data to be decrypted. Must be a string.

Returns

A string representing the decrypted data.

Throws

TypeDescription
ReferenceErrorIf the encrypted value is undefined.
TypeErrorIf the encrypted value is not a string.

Example

const encrypted = crypto.encrypt('This is my secret message');
const decrypted = crypto.decrypt(encrypted);

Security Considerations

When using CryptoDriver, it's important to keep in mind the following security considerations:

  • Always use a strong encryption key. This means using a key that is long, random, and not easily guessable.
  • Do not hardcode your encryption key in your application code. Instead, consider using an environment variable or other secure method for storing your key.
  • Make sure to handle your encrypted data securely, especially when transmitting it over a network or storing it in a database. This may involve using additional security measures such as HTTPS or SSL/TLS.

Contributing

If you encounter any bugs or issues with CryptoDriver, please open an issue on the GitHub repository. Pull requests are also welcome!

License

CryptoDriver is released under the MIT License.

2.0.5

12 months ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago