GithubHelp home page GithubHelp logo

keychain's Introduction

NOTICE

We’re archiving Anvil Connect and all related packages. This code is entirely MIT Licensed. You’re free to do with it what you want. That said, we are recommending against using it, due to the potential for security issues arising from unmaintained software. For more information, see the announcement at anvil.io.

KeyChain for use with Web Cryptography API in Node.js

Usage

Install the package

$ npm install https://github.com/anvilresearch/keychain.git

Load the module

const KeyChain = require('keychain')

Create a new instance by passing a descriptive object to the KeyChain constructor. This object can have any naming or nesting scheme, as long as the last nested object contains parameters describing key generation. At a bare minimum, this must include an alg property with a JWA algorithm name as its value. Currently, RS256, RS384, and RS512 are supported.

let keys = new KeyChain({
  a: { b: { alg: 'RS256' } },
  c: { d: { alg: 'RS256' } },
  e: { f: { alg: 'RS256', modulusLength: 2048 } // default is 4096
}) 

This initialized a KeyChain instance but didn't generate keys. To generate keys according to the object passed to the keychain, call rotate(). The rotate() method returns a promise for the keychain.

keys.rotate()

Once keys have been generated, they can be accessed as CryptoKey or JWK objects, according to the object structure defined by the caller.

Access CryptoKey objects for Web Crypto API operations:

keys.a.b.privateKey
keys.a.b.publicKey

Access JWK objects:

keys.a.b.privateJwk
keys.a.b.publicJwk

Key rotation also generates a JWK Set in object and JSON form:

keys.jwks     // JWK Set object
keys.jwkSet   // JWK Set JSON string

Running tests

Nodejs

$ npm test

MIT License

Copyright (c) 2016 Anvil Research, Inc.

keychain's People

Contributors

christiansmith avatar dmitrizagidulin avatar eternaldeiwos avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

keychain's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.