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

basic-crypter

v1.0.2

Published

Data Encryption and Decryption wrapper around node js crpto module, Uses scrypt for key deriviation and handles the data encryption algorithm independent via <code>crypto.createCipheriv</code>. supports all algorithms that are able to use auth tags

Downloads

204

Readme

Data Encrypter and Decrypter

Encrypts and decrypts data using scrypt for key deriviation and all availiable algorithms in crypto.createCipherIv, this is just a wrapper for the node crypto module which does all the heavy lifting

Usage

Make sure the key is an object that can be interpreted as a buffer If the program fails to generate a buffer from the key it will throw The Default algorithm is aes-256-gcm

import { DataCrypter } from "basic-crypter"

const crypter = new DataCrypter();

const key = "test";
const data = "Very Secret Data";

const encrypted_data = await crypter.EncryptData(data,key);
const decrypted_data = await crypter.DecryptData(encrypted_data,key);

if (decrypted_data === data){
    console.log("Success!");
}

Use a Different Algorithm

Currently only algorithms that are able to use auth tags are supported. If there is demand for it i will make it so others work as well create a github issue. If you attempt to use an algorithm that does not support auth tags it will throw. If you put in the wrong values for key size and iv size it will throw.

import { DataCrypter } from "basic-crypter"

// algorithm, key size (bytes), iv size (bytes)
const crypter = new DataCrypter("chacha20-poly1305", 32, 12);

const key = "test";
const data = "Very Secret Data";

const encrypted_data = await crypter.EncryptData(data,key);
const decrypted_data = await crypter.DecryptData(encrypted_data,key);

if (decrypted_data === data){
    console.log("Success!");
}

Encoding of input and output

By default the ouput of encryptData is a buffer and the output of decryptData is in utf8. Here is how you can change it.

import { DataCrypter } from "basic-crypter"

// leave rest undefined to use default options 
// ascii is the output encoding and hex the data encoding to use on input to decrypt and output on encrypt
const crypter = new DataCrypter(undefined,undefined,undefined,"ascii","hex");

const key = "test";
const data = "Very Secret Data";

const encrypted_data = await crypter.EncryptData(data,key);
console.log(encrypted_data); // in hex
const decrypted_data = await crypter.DecryptData(encrypted_data,key);
console.log(decrypted_data); // in ascii

if (decrypted_data === data){
    console.log("Success!");
}

Supported Algorithms

Depends on node crypto.createCipherIv() The Algorithm must support node cipher.getAuthTag() If you are unsure if the algorithm is supported just try it out or use the default which should be fine for most use cases Run openssl list -cipher-algorithms in your terminal to see availiabe algorithms (this does not mean that they are supported)

Source Code and License

See github