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

@runninghill/simple-encryption

v1.1.0

Published

A package that allows you to simply encrypt and decrypt data.

Downloads

48

Readme

Runninghill Logo

Simple Encryption

Please note that this is the README for CONSUMERS, if you plan on contributing to this package, please take a look here.

A simple encryption package that allows you to encrypt and decrypt data.

Getting Started 🏁

If you plan on contributing to the package, please read the contributor readme.

  1. Run npm install @runninghill/simple-encryption.

  2. Import and use the exposed classes to encrypt/decrypt your data.

Usage 💡

To begin using Simple Encryption, create an instance of the Encryptor class, passing in the appropriate configuration (optional).

It is recommended that you configure the secret, this is your private key for the encryption.

To understand what you can configure, check out the API reference.

NB: In order to decrypt data, the configuration of the Encryptor instance must be the same as the one used to initially encrypt the data.

const { Encryptor } = require('@runninghill/simple-encryption')

const encryptor = new Encryptor({
    saltRounds: 15,
    secret: 'a9479590-299c-4812-9636-a333a97ca6cc'
})

To encrypt data, simply call the encrypt method:

const user = {
    name: 'John',
    surname: 'Doe',
    age: 31
}

const encryption = await encryptor.encrypt(user)

To decrypt data, simply call the decrypt method:

const decryptedData = await encryptor.decrypt(encryption)
// decryptedData = {
//     name: 'John',
//     surname: 'Doe',
//     age: 31
// }

API Reference 📖

Classes

Encryptor

A class that allows you to encrypt and decrypt data. It also provides optional configuration.

Configuration

|Name|Type|Description|Default| |----|----|-----------|-------| |secret|string|the private key for the encryption|'default'| |saltRounds|number|the amount of rounds to generate the salt, used in the creation of the encryption key. The greater the amount of rounds the more resource intensive the encryption will be|true| |saltPlacementStrategy|SaltPlacementStrategy|the strategy for placing the salt in the encryption|SaltPlacementStrategy.Before

Methods

Encrypt

Encrypts the provided data using the configuration of the Encryptor instance.

The provided data can be primitive or an object.

Returns: a promise with a string, the encrypted data with the salt placed inside it.

Parameters

|Name|Type|Description|Default| |----|----|-----------|-------| |data|any|the data to be encrypted|

Decrypt

Decrypts the provided encryption using the configuration of the Encryptor instance.

Returns: a promise with the primitive data or object that was encrypted

Parameters

|Name|Type|Description|Default| |----|----|-----------|-------| |encryption|string|the result from the encrypt method; the encrypted data with the salt placed inside it|


Enums

SaltPlacementStrategy

Determines how the salt is placed in the encrypted data

Values

|Name|Description| |----|-----------| |Before|the salt is placed before the encrypted data| |After|the salt is placed after the encrypted data|