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

just-encrypt-me

v0.1.1

Published

An opinionated, simplified encryption library on top of the Web Crypto API.

Downloads

1

Readme

NOTE: just-encrypt-me is still a pre-release project (v0.x.x). Please use at your own risk. If you find this project useful, please consider leaving a star so others can find it. Thanks!

What?

This library takes a few of the best methods from the Web Crypto API and simplifies it to make encryption easier (with pretty good defaults based on best practices).

  • ✨ Simplifies encryption while following best security practices.
  • 🚀 Works in browsers, web workers, node and electron. React Native not tested.
  • 🔑 Asymmetric encryption coming soon.

Opinionated, how?

  • Has only 1 type of symmetric encryption mode (AES-GCM-256) from the Web Crypto API (based on best practices and imo)
  • Password key derivation will do 500,000 iterations by default (minimum, can set higher, but not lower)
  • Has only 1 hash method (SHA256)
  • Expects UTF-8 everywhere input
  • Nonce, salt and IV are simply referred to as "seed" in all function arguments. Avoids confusion. Simplifies the library even further.

If you need to use the other types of encryption mode or tweak any other settings, this library is not what you're looking for.

Install

npm install just-encrypt-me

or with yarn

yarn add just-encrypt-me

Usage

Encrypt text

import { encrypt, generateSeed } from 'just-encrypt-me';

const password = 'somestrongpassword';
const seed = generateSeed();

const encrypted = await encrypt('Hello, World!', password, seed);

// export the base64 of the encrypted text
const base64 = encrypted.base64(); // 4AZS2rs2OZ4j5u9BM68TsMzXo1silVZ2UvRkiTE=

// or the buffer
const buffer = encrypted.buffer(); // <Buffer e0 06 52 ...>

Save the seed and base64 or buffer to your database for later decryption. password is the only sensitive info here so you can save the seed in plain text.

Decrypt text

import { decrypt } from 'just-encrypt-me';

// decrypt from a base64 string
const decrypted = decrypt(base64, password, seed);
console.log(decrypted.string()); // Hello, World!

// or decrypt from buffer
const decrypted = decrypt(buffer, password, seed);
console.log(decrypted.string()); // Hello, World!

Hash a message

import { hash } from 'just-encrypt-me';

const hashed = hash('some message');
console.log(hashed); // 6yAa9arw1gYp09KmHkZs/A/ttRet2DHsrFI14dqpY9Y=

Derive key from password

At some point you may want to encrypt multiple items without using the plain text password every time, or you may want to have different seeds for each items. For that you can derive a key from the plain text password and use the key for all encryption/decryption.

import { deriveKey, generateSeed } from 'just-encrypt-me';

const password = 'somestrongpassword';
const seed = generateSeed();

const key = await deriveKey(password, seed);

Encrypt text using a key

import { encryptWithKey, generateSeed } from 'just-encrypt-me';

const seed2 = generateSeed();

const encrypted = await encryptWithKey('Hello, World!', key, seed2);

Here we are using 2 separate seeds for the password and text encryption. You will need to save both in your database for later decryption. Again, password is the only sensitive info here so you can save seed and seed2 in plain text.

The key is a CryptoKey object. Don't save this to your database, it may be unsafe. Instead, you should call the deriveKey method whenever needed.

Decrypt text using a key

import { decrypt } from 'just-encrypt-me';

// decrypt from a base64 string
const decrypted = decryptWithKey(base64, key, seed2);
console.log(decrypted.string()); // Hello, World!

// or decrypt from buffer
const decrypted = decryptWithKey(buffer, key, seed2);
console.log(decrypted.string()); // Hello, World!

Maintainers

License

This project is licensed under the terms of the MIT license.