EternalDeiwos / keyto

A utility for translating cryptographic keys between representations
https://eternaldeiwos.github.io/keyto
MIT License
10 stars 6 forks source link
base64 base64url der hex jose jwk node node-js nodejs pem webcrypto

Keyto (@trust/keyto)

standard-readme compliant Build Status codecov

A utility for translating cryptographic keys between representations.

Keyto is pronounced 'key-to'.

Full project documentation is available here.

Table of Contents

Status

RSA

ECDSA - secp256k1 (Blockchain Curve)

ECDSA - secp256r1 (P-256)

ECDSA - secp384r1 (P-384)

ECDSA - secp521r1 (P-521)

EDDSA - ed25519

EDDSA - ed448

Install

$ npm install @trust/keyto --save

Usage

Translate Private PEM to Public JWK:

const keyto = require('@trust/keyto')

let pemPrivate = getPrivatePemStringSomehow()
let jwk = getPublicJwkSomehow()

// String data can either be passed in directly:
let key = keyto.from(pemPrivate, 'pem').toJwk('public')

// Or can be passed in as an object instead:
let key = keyto.from({ key: pemPrivate }, 'pem').toJwk('public')
assertEqual(jwk, key)

Translate Private Hex (Blockchain) Key to PKCS8 Public PEM:

const keyto = require('@trust/keyto')

let blk = getPrivateBlockchainHexStringSomehow()
let pemPublic = getPublicPemSomehow()

let key = keyto.from(blk, 'blk').toString('pem', 'public_pkcs8')
assertEqual(pemPublic, key)

API

keyto.from(key, format) -> {Key}

args:

format:

Format can be any of these: 'pem', 'jwk' or 'blk'.

{Key}.toJwk(selector = 'public') -> {JWK}

args:

selector:

Selector can be any of these: 'public', 'private'.

{Key}.toString(format = 'pem', selector = 'public') -> {String}

args:

format:

Format can be any of these: 'pem', 'jwk' or 'blk'.

selector:

Selector can be any of these: 'public', 'private', 'public_pkcs1', 'public_pkcs8', 'private_pkcs1' or 'private_pkcs8'.

Maintainers

@EternalDeiwos @thelunararmy

Contribute

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2017-2020 Greg Linklater