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

@hyperar/eckey-utils

v0.7.14

Published

Node.js based EC key utilities that can generate PEM keys (required by crypto.sign and crypto.verify) from the raw ones usually but not necessarily generated by crypto.ECDH

Downloads

184

Readme

A fork of eckeyUtils with JSDoc generated types

eckeyUtils

Node.js based EC key utilities to generate the PEM contents (required by crypto.Sign and crypto.Verify) from the raw keys generated by crypto.ECDH and to parse key info from given PEM content. The lastest update has added JWK support.

Motivation

Namely the ECDH.generateKeys function should be used to generate EC keys for the key-exchange purpose, but actually the keys it generates are bare/raw ec private key (i.e., d in the cryptographic context) and ec public key (the relevant EC point, calculated from base point G and d), so supposedly there's no obstacle to use it in ECSDA scenario except that the crypto.Sign and crypto.Verify function doesn't support using raw key directly. This library comes out to bridge this gap by converting raw keys to PEM keys.

On the other side, this library provides a symmetrical function to parse key info (private key PEM -> {privateKey, curveName, publicKey?}, public key PEM -> {curveName, publicKey}) from the given EC PEM content, and such information can be used by crypto.ECDH.

P.s., the latest update: added JWK support - generation and parse.

CAUTION

Some people argue that use one key pair for both ECDH and ECDSA will compromise the security, so please try to avoid using one key pair for both usages except that you know dearly that there's no negative byeffect.

Usage

Generate PEM from raw keys

const crypto = require('crypto'), ecKeyUtils = require('eckey-utils');
const curveName = 'secp256k1';

const ecdh = crypto.createECDH(curveName);
ecdh.generateKeys();

const pems = ecKeyUtils.generatePem({
	curveName,
	privateKey: ecdh.getPrivateKey(),
	publicKey: ecdh.getPublicKey()
});

const sign = crypto.createSign('sha256');
const message = Buffer.from('Hello, World!');
sign.update(message);
let sig = sign.sign(pems.privateKey);

const verify = crypto.createVerify('sha256');
verify.update(message);
console.log(verify.verify(pems.publicKey, sig));

Parse key information from PEM

const ecKeyUtils = require('eckey-utils');

console.log(ecKeyUtils.parsePem(`-----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIBL1+Q5pDjC9ijZg/XCBhaJrV8pM+v/XgcwC53sWRFK69paB9zzVAD
ZqzrgXOAghxqWx0QEG8RhvXowXzMOuLmHz2gBwYFK4EEACOhgYkDgYYABAAlLIp1
uSSj9wjrpr4+9UitBXtEwB5AAS/PHyK/FLvM0Ybz0PDeg8RTqKXJziwz0i0AjvWp
FQSyuJe5PXesKhRzXQDqJQTijoekz5mWOdYLRnKln0B87JrXbpx+R0slrEJzPeHo
7fv+DaM09Dfvy30CLHhzaGqRpesz+rvPVKYCyun8EQ==
-----END EC PRIVATE KEY-----`));

console.log(ecKeyUtils.parsePem(`-----BEGIN PUBLIC KEY-----
MD4wEAYHKoZIzj0CAQYFZysBBAkDKgAEgiGotjsUDWG11VFfkBsSoscOvrH27hjw
6bHXZwpyLjXW19Th2MRYGg==
-----END PUBLIC KEY-----`));

Dependencies

Node.js version later than 5.x

License

Written in 2018 by tibetty [email protected]