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

crypto-driver

v2.0.5

Published

CriptoDriver class related to cipher and decipher of data.

Downloads

15

Readme

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

| Name | Type | Description | |------------|----------|-----------------------------------------------------------------------------------------| | password | string | The password used for encryption and decryption. Must be a string of 32 characters. |

Throws

| Type | Description | |------------------|--------------------------------------------| | ReferenceError | If the password value is undefined. | | TypeError | If 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

| Name | Type | Description | |--------|----------|-----------------------------------------------| | data | string | The data to be encrypted. Must be a string. |

Returns

A string representing the encrypted data.

Throws

| Type | Description | |------------------|----------------------------------------| | ReferenceError | If the data value is undefined. | | TypeError | If 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

| Name | Type | Description | |-------------|----------|---------------------------------------------------------| | encrypted | string | The encrypted data to be decrypted. Must be a string. |

Returns

A string representing the decrypted data.

Throws

| Type | Description | |------------------|---------------------------------------------| | ReferenceError | If the encrypted value is undefined. | | TypeError | If 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.