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

dhkea-js

v1.0.0

Published

A high performance javascript implementation of Diffie–Hellman Key Exchange algorithm. Dhkea.JS implements all MODP groups defined in RFC2409 and RFC3526.

Downloads

6

Readme

Dhkea.JS

A high performance javascript implementation of Diffie–Hellman Key Exchange algorithm. Dhkea.JS implements all MODP groups defined in RFC2409 and RFC3526.

Features

  • :rabbit: Implements all MODP groups defined in RFC2409 and RFC3526
  • :rabbit: High performance
  • :rabbit: Support both Node.JS and browser side
  • :rabbit: Full typescript support is provided

Installation

npm install dhkea-js

If you are using yarn, you can use

yarn add dhkea-js

instead.

Usage

  const { generateIndividualKey, getSharedKey } = require('dhkea-js');

  // Alice's individual key, containing private key and public key
  const aliceKey = generateIndividualKey(); 

  // Bob's individual key
  const bobKey = generateIndividualKey();

  // Alice can get the shared key via her private key and bob's public key
  const sharedKeyCaculatedByAlice = getSharedKey(aliceKey.privateKey, bobKey.publicKey);

  // Bob can get the shared key via his private key and alice's public key
  const sharedKeyCaculatedByBob = getSharedKey(bobKey.privateKey, aliceKey.publicKey);

  // Diffie–Hellman Key Exchange algorithm gurantees that these two keys are the same
  console.log(sharedKeyCaculatedByAlice === sharedKeyCaculatedByBob); // true

MODP Group

MODP group is first defined in RFC2409 to do the Diffie-Hellman Key Exchange and is later extended in RFC 3526. Each MODP group contains the prime and its generator.

Dhkea.JS implements all the MODP groups defined in RFC2409 and RFC3526, with id 1, 2, 5, 14, 15, 16, 17, 18 whose bit length of the prime is 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192 respectively.

API

generateIndividualKey()

Syntax

  generateIndiviualKey(bitLen?: ModpBitLen): {
    privateKey: bigint;
    publicKey: bigInt;
  }

Generate an indiviual key pair with the MODP group with bit length bitLen. If bitLen is omited, the 2048-bits MODP Group(id = 14) will be used.

getSharedKey()

Syntax

getSharedKey(myPrivatedKey: bigint, theirPublicKey: bigint, bitLen?: ModpBitLen): bigint

Calculate the shared keys from my private key and their public key, using the MODP Group with bit length bitLen. If bitLen is omited, use the default 2048-bits MODP Group(id = 14).

getModpGroupInfo()

Syntax

getModpGroupInfo(bitLen: ModpBitLen): {
  id: ModpGroupId;
  generator: bigint;
  bitLen: ModpBitLen;
  prime: bigint;
}

Get the info of the MODP Group with bit length bitLen.

License

Dhkea.JS is licensed under GNU Lesser General Public License 2.1.