Code Monkey home page Code Monkey logo

js-jose's Introduction

Javascript library for Jose JWE

license build coverage

Overview

JavaScript library to encrypt/decrypt data in JSON Web Encryption (JWE) format. This library is designed to work in the browser (tested in Chrome 38). It can do RSA-based public/private crypto as well as shared key.

JWE is an encapsulation format which makes it easy to share ciphertext between different platforms: data encrypted in a browser can be decrypted in Go, Java, etc.

The library uses compact representation. There is therefore no support for multiple recipients. It should be easy to add that if needed.

The library partially supports extra headers.

The library uses the Web Crypto API, which is available in recent browsers (http://caniuse.com/#feat=cryptography). As of March 2015, it seems ~68% of users have some form of Web Crypto support.

This code has been tested in Chrome 38 and is compatible with the Golang implementation.

JSON web encryption is currently a set of drafts. This code is based on the following drafts:

Disclaimer: This library contains encryption software that is subject to the U.S. Export Administration Regulations. You may not export, re-export, transfer or download this code or any part of it in violation of any United States law, directive or regulation. In particular this software may not be exported or re-exported in any form or on any media to Iran, North Sudan, Syria, Cuba, or North Korea, or to denied persons or entities mentioned on any US maintained blocked list.

Example encryption

<script src="jose-jwe.min.js"></script>
var joseJWE = new JoseJWE();
var rsa_key = JoseJWE.Utils.importRsaPublicKey({
	"n": "c2:4b:af:0f:2d:2b:ad:36:72:a7:91:0f:ee:30:a0:95:d5:3a:46:82:86:96:7e:42:c6:fe:8f:20:97:af:49:f6:48:a3:91:53:ac:2e:e6:ec:9a:9a:e0:0a:fb:1c:db:44:40:5b:8c:fc:d5:1c:cb:b6:9b:60:c0:a8:ac:06:f1:6b:29:5e:2f:7b:09:d9:93:32:da:3f:db:53:9c:2e:ea:3b:41:7f:6b:c9:7b:88:9f:2e:c5:dd:42:1e:7f:8f:04:f6:60:3c:fe:43:6d:32:10:ce:8d:99:cb:76:f7:10:97:05:af:28:1e:39:0f:78:35:50:7b:8e:28:22:a4:7d:11:51:22:d1:0e:ab:6b:6f:96:cb:cf:7d:eb:c6:aa:a2:6a:2e:97:2a:93:af:a5:89:e6:c8:bc:9f:fd:85:2b:0f:b4:c0:e4:ca:b5:a7:9a:01:05:81:93:6b:f5:8d:1c:f7:f3:77:0e:6e:53:34:92:0f:48:21:34:33:44:14:5e:4a:00:41:3a:7d:cb:38:82:c1:65:e0:79:ea:a1:05:84:b2:6e:40:19:77:1a:0e:38:4b:28:1f:34:b5:cb:ac:c5:2f:58:51:d7:ec:a8:08:0e:7c:c0:20:c1:5e:a1:4d:b1:30:17:63:0e:e7:58:8e:7f:6e:9f:a4:77:8b:1e:a2:d2:2e:1b:e9",
    "e": 65537
});
joseJWE.encrypt(rsa_key, "hello world").then(function(result) {
	console.log(result);
}).catch(function(err){
	console.error(err);
});

Algorithms exposed by this library

Key Encryption:

  • RSA-OAEP (default)
  • RSA-OAEP-256
  • A128KW (supported, but not recommended for use)
  • A256KW (supported, but not recommended for use)

Content Encryption:

  • A256GCM (default)
  • A128GCM
  • A128CBC-HS256
  • A256CBC-HS512

Algorithms not exposed (and reason why)

  • DIR (could be added if deemed useful, would require little work)
  • PBES2-HS256+A128KW (would require implementing PBES2)
  • PBES2-HS512+A256KW (would require implementing PBES2)
  • RSAES-PKCS1-v_5 was removed in Chrome (https://code.google.com/p/chromium/issues/detail?id=372920)
  • PBES2-HS384+A192KW (AES with 192-bit keys isn't supported in Chrome)
  • A192KW (AES with 192-bit keys isn't supported in Chrome)
  • ECDH-ES (Chrome and IE currently don't support it)
  • ECDH-ES+A128KW (Chrome and IE currently don't support it)
  • ECDH-ES+A192KW (Chrome and IE currently don't support it)
  • ECDH-ES+A256KW (Chrome and IE currently don't support it)
  • RSA-PSS, ECDSA (could be added once Chrome supports these)

Building

npm install
grunt

Some background info

The Web Crypto API is still pretty new and isn't always very well documented. The following resources are useful:

Note: Internet Explorer's Web Crypto API differs from Chrome's (as it was implemented against an earlier version of the ietf draft). We will either need to implement a thin abstraction layer or wait for Microsoft to update things.

Random other interesting resources

js-jose's People

Contributors

alokmenghrajani avatar csstaub avatar dgalling avatar emerose avatar

Watchers

 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.