Git Product home page Git Product logo

easy-jose's Introduction

easy-jose

Status npm version

Javascript Object Signing and Encryption standard

Straightforward encryption/decryption utility based on node-jose by Cisco

Getting Started

Install via NPM

$ npm install --save easy-jose

Basic Usage

Require the library, then initialize.

const easyJose = require('easy-jose');
easyJose.init();

Generating Keys: generateKeys()

Returns an object with public_key and private_key

Optional Arguments:

  • kty: key type, default is "RSA"
  • size: size in bits, default is 2048
  • isEncoded: boolean, base64 encode the public key, default is false
  • isPadded: boolean, add padding to base64 encoding, default is false

Example:

const keys = easyJose.generateKeys("EC", 4096);

Encrypting Content: encryptContent()

Required Arguments:

  • public_key
  • payload: data to encrypt

Optional Argument

  • isKeyEncoded: boolean, tell easyJose if you're using a base64 encoded public_key

Example:

const encrypted = easyJose.encryptContent(public_key, payload);

Decrypting Content: decryptContent()

Required Arguments:

  • private_key
  • payload: data to decrypt

Optional Argument

  • isPayloadEncoded: boolean, tell easyJose if you're using a base64 encoded payload

Example:

const decrypted = easyJose.decryptContent(private_key, encrypted);

Example Implementation

const easyJose = require('easy-jose');
const somedata = {
  txt: 'hello'
};

(async () => {
  easyJose.init();
  const { private_key, public_key } = await easyJose.generateKeys();
  console.log(private_key);
  console.log(public_key);

  const encrypted = await easyJose.encryptContent(public_key, somedata);
  console.log(encrypted);

  const decrypted = await easyJose.decryptContent(private_key, encrypted);
  console.log(decrypted);
})();

Utilities

Base64 Encoder

const encoded = easyJose.encode(raw);

Base64 Decoder

const decoded = easyJose.decode(base64EncodedString);

Array Buffer converter

const u8a = easyJose.convertToU8A(data);

Array Buffer Decoder

const data = easyJose.convertU8A(arrayBufferData);

Thanks

easy-jose* © 2018, Fernan de Dios. Released under the MIT License.

fernandedios.com  ·  GitHub @fernandedios  ·  Twitter @fernan_de_dios

easy-jose's People

Contributors

fernandedios avatar

Watchers

James Cloos avatar  avatar

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.