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

cwi-crypto

v0.1.8

Published

Common implementations for standard cryptographic utilities

Downloads

576

Readme

cwi-crypto

This module provides a common implementation for standard cryptographic utilities, ciphers, IV management, low-level promitives and operations.

Exported Functions

Names | Description -------------------------|----------------------------- encrypt and decrypt | Symmetric AES-GCM encryption with a 32-byte prepended IV and support for data encoded as a Uint8Array or a string XOR | Bitwise Exclusive-OR between two Uint8Arrays of equal length keyFromString | Derives a CryptoKey from a string with PBKDF2 using a sane iteration count and the given salt

API

encrypt(plaintext: Uint8Array|string, key: CryptoKey, returnType: string) => ciphertext: Uint8Array|string

Encrypts the given plaintext with the given key. Returns the ciphertext.

Parameters

Name | Description -----------|------------- plaintext | The data to encrypt. May be a String or a Uint8Array key | The CryptoKey object to use for the encryption operation returnType | A string indicating the desired return type. May be either string (default) or Uint8Array

Return Value

The function will either return a string or a Uint8Array representing the ciphertext, depending on the value of returnType.

decrypt(ciphertext: Uint8Array|string, key: CryptoKey, returnType: string) => plaintext: Uint8Array|string

Decrypts the given ciphertext with the given key. Returns the plaintext.

Parameters

Name | Description -----------|------------- ciphertext | The data to decrypt. May be a String or a Uint8Array key | The CryptoKey object to use for the decryption operation returnType | A string indicating the desired return type. May be either string (default) or Uint8Array

Return Value

The function will either return a string or a Uint8Array representing the plaintext, depending on the value of returnType.

keyFromString({ string: String, salt: Uint8Array }) => key: CryptoKey

Derives a suitable CryptoKey from the password string with PBKDF2 and the given salt.

Parameters

Name | Description -----------|------------- string | The password string to use salt | a Uint8Array representing the password salt to use

Return Value

The function will return a CryptoKey object representing the derived key.

XOR(k1: Uint8Array, k2: Uint8Array) => result: Uint8Array

Performs a bitwise exclusive OR operation with the given data. Returns the result. Inputs must be the same length.

Parameters

Name | Description --------|------------- k1 | A Uint8Array representing the first input to XOR k2 | A Uint8Array representing the second input to XOR

Return Value

The function will return a Uint8Array containing the output data.

Testing

While this is not a React application, the react-scripts package is used for testing. I tried to get Jest to work on its own with the Web Cryptography API, TextEncoder and TextDecoder, but was unable to find a suitable configuration. If anyone can get the tests to pass with only Jest, please feel free to create a pull request.

Adequate testing practices for use in a critical production application should be observed at all times for this library.

License

The license for the code in this repository is the Open BSV License.