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 🙏

© 2021 – Pkg Stats / Ryan Hefner

@encipher/web-crypto

v1.0.0-beta.0

Published

A promised based easy to use wrapper over Web Crypto APIs

Downloads

6

Readme

Web Crypto

A promised based easy to use wrapper and services built using Web Crypto APIs

-! NOTE: This is a WIP library.
-! APIs may change drastically till we release a stable version.
-! Please watch this repo for updates.

The objective of this library is to provide some wrapper methods and services which are very easy to use to perform cryptographic operations in the browser.

This library internally uses Web Crypto browser APIs, so this library can't run on any browser which does't support Web Crypto APIs. Also note that Web Crypto APIs are only available in secure context (HTTPS) even in modern browsers.

For more information on Web Crypto API browser support, click here

For reporting any kind of issues please use the issues tracker. For general discussion, feature request use the discussions.

Installations

npm install @encipher/web-crypto --save

Examples:

Key Generations

import {
  KeyGenerator,
  KeyGeneratorMaps,
} from '@encipher/web-crypto';


// Generating a RSA key pair
const keyAlgorithm = {
  name: KeyGeneratorMaps.rsaKeyGenerationAlgorithmsMap['RSA-OAEP'],
  modulusLength: 4096,
  publicExponent: new Uint8Array([1, 0, 1]),
  hash: KeyGeneratorMaps.rsaKeyHashFunctionsMap['SHA-256'],
};

const keyGen = new KeyGenerator(algorithm);

// Generate as many keys as you want with the keyGen object
let rsaKeyPair1;
let rsaKeyPair2;

keyGen.generateKey().then(data => {
  rsaKeyPair1 = data;
})

keyGen.generateKey().then(data => {
  rsaKeyPair2 = data;
})

Encrypting a key with a passphrase

It's often required that you need to export a private key, like for server side storage. Before that you want to encrypt the key with a passphrase. This library provides some utils functions to do that easily.

Wrap (encrypt) a key with a AES-CBC-256 key derived using PBKDF2 and a passphrase

import {
  wrapKeyWithAesCbc256,
} from '@encipher/web-crypto';


const passphrase = "This is really a secret";

let wrappedKey;

wrapKeyWithAesCbc256(
  passphrase,
  rsaKeyPair.privateKey,
).then((data) => {
  wrappedKey = data;
});

Encrypting & Decrypting a payload (With RSA key pair)

const encryptionAlgorith = {
    name: 'RSA-OAEP',
  };

// rsaKeyPair generated with KeyGenerator as shown above
const cipher = new Cipher(
  encryptionAlgorith,
  rsaKeyPair.publicKey,
  rsaKeyPair.privateKey,
);

const encoder = new TextEncoder();
const decoder = new TextDecoder();

const cipherText = await cipher.encrypt(encoder.encode('Hello World'));
let plainText = await cipher.decrypt(cipherText);
plainText = decoder.decode(plainText)

Many more comming soon...