jws vs jwa vs jose vs jsonwebtoken vs node-jose
JavaScript JWT and JWK Libraries
jwsjwajosejsonwebtokennode-joseSimilar Packages:
JavaScript JWT and JWK Libraries

These libraries provide functionalities for creating, signing, verifying, and decoding JSON Web Tokens (JWT) and JSON Web Keys (JWK). They are essential for implementing authentication and authorization in web applications, allowing secure transmission of information between parties. Each library has its unique features, performance characteristics, and use cases, making them suitable for different scenarios in web development.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
jws46,193,37072418.8 kB322 months agoMIT
jwa45,503,47910214.1 kB169 months agoMIT
jose36,015,5497,284258 kB02 months agoMIT
jsonwebtoken31,645,17318,14243.4 kB1852 months agoMIT
node-jose792,993724353 kB703 years agoApache-2.0
Feature Comparison: jws vs jwa vs jose vs jsonwebtoken vs node-jose

Standards Compliance

  • jws:

    JWS is dedicated to the JSON Web Signature standard, providing a focused implementation for signing and verifying data according to the JWS specification.

  • jwa:

    JWA is specifically designed for implementing the signing and encryption algorithms defined in the JOSE specifications, ensuring compliance with those standards.

  • jose:

    JOSE is built to comply with the full suite of JOSE standards, including JWT, JWS, JWE, and JWK, making it a versatile choice for applications requiring adherence to security standards.

  • jsonwebtoken:

    jsonwebtoken focuses primarily on JWT, ensuring compliance with the JWT specification but not the broader JOSE standards, making it simpler but less comprehensive.

  • node-jose:

    node-jose supports various JOSE standards and provides a high-level API for working with JWTs and JWKs, ensuring compliance with relevant specifications.

Ease of Use

  • jws:

    JWS is user-friendly for those specifically focused on signing and verifying data, with a clear API that simplifies the process.

  • jwa:

    JWA provides a modular approach that is straightforward for developers familiar with cryptographic concepts, but it may require additional understanding of the underlying algorithms.

  • jose:

    JOSE offers a comprehensive API that may have a steeper learning curve due to its extensive feature set, but it provides powerful capabilities once mastered.

  • jsonwebtoken:

    jsonwebtoken is known for its simplicity and ease of use, making it an excellent choice for developers who need quick JWT implementation without complex configurations.

  • node-jose:

    node-jose has a more complex API due to its advanced features, which may require a deeper understanding of cryptographic principles.

Performance

  • jws:

    JWS is designed for high performance in signing and verification processes, ensuring minimal latency in applications that require frequent data integrity checks.

  • jwa:

    JWA's performance is dependent on the specific algorithms used, but it is generally efficient for applications that require modular cryptographic functionalities.

  • jose:

    JOSE's performance is robust, but its comprehensive feature set may introduce overhead for simple use cases. It is optimized for applications that require extensive cryptographic operations.

  • jsonwebtoken:

    jsonwebtoken is lightweight and optimized for performance, making it ideal for applications that need fast JWT creation and verification without additional overhead.

  • node-jose:

    node-jose may have a performance overhead due to its extensive features, but it is optimized for applications that require complex cryptographic operations.

Key Management

  • jws:

    JWS does not include key management capabilities, focusing solely on signing and verification, which may necessitate external key management solutions.

  • jwa:

    JWA focuses on the algorithms and does not include key management features, requiring developers to implement their own solutions for handling keys.

  • jose:

    JOSE provides advanced key management features, including support for key rotation and storage, making it suitable for applications with stringent security requirements.

  • jsonwebtoken:

    jsonwebtoken does not provide built-in key management features, relying on developers to manage keys externally, making it less suitable for applications requiring complex key management.

  • node-jose:

    node-jose offers high-level key management features, allowing for easier handling of keys and integration with JWTs, making it suitable for applications needing robust key management.

Extensibility

  • jws:

    JWS is primarily focused on signing and verification, with limited extensibility options, making it less suitable for applications needing custom features.

  • jwa:

    JWA allows for extensibility through its modular approach, enabling developers to implement additional algorithms as needed.

  • jose:

    JOSE is highly extensible, allowing developers to implement custom algorithms and features, making it suitable for applications with unique security requirements.

  • jsonwebtoken:

    jsonwebtoken is less extensible, focusing on standard JWT functionalities without support for custom algorithms or extensions.

  • node-jose:

    node-jose is extensible and allows for custom implementations, making it a good choice for applications that require tailored cryptographic solutions.

How to Choose: jws vs jwa vs jose vs jsonwebtoken vs node-jose
  • jws:

    Use JWS if your primary need is to create and verify JSON Web Signatures. It is a specialized library that simplifies the process of signing and verifying data, making it suitable for applications that need to ensure data integrity and authenticity without additional features.

  • jwa:

    Opt for JWA if you need a library focused specifically on the signing and verification algorithms used in JWTs. It is useful for applications that require a modular approach to handling different cryptographic algorithms without the full overhead of a larger library.

  • jose:

    Choose JOSE if you need a comprehensive library that supports a wide range of JOSE standards (JWT, JWS, JWE, JWK) and requires advanced features like key management and encryption. It is well-suited for applications that need robust security features and compliance with various standards.

  • jsonwebtoken:

    Select jsonwebtoken for a straightforward solution to create and verify JWTs. It is lightweight and easy to use, making it ideal for projects that require basic JWT functionalities without the overhead of additional features.

  • node-jose:

    Choose node-jose if you require a library that provides a high-level API for working with JSON Web Tokens and Keys, including support for key management and encryption. It is particularly useful for applications that need to handle complex cryptographic operations.

README for jws

node-jws Build Status

An implementation of JSON Web Signatures.

This was developed against draft-ietf-jose-json-web-signature-08 and implements the entire spec except X.509 Certificate Chain signing/verifying (patches welcome).

There are both synchronous (jws.sign, jws.verify) and streaming (jws.createSign, jws.createVerify) APIs.

Install

$ npm install jws

Usage

jws.ALGORITHMS

Array of supported algorithms. The following algorithms are currently supported.

alg Parameter ValueDigital Signature or MAC Algorithm
HS256HMAC using SHA-256 hash algorithm
HS384HMAC using SHA-384 hash algorithm
HS512HMAC using SHA-512 hash algorithm
RS256RSASSA using SHA-256 hash algorithm
RS384RSASSA using SHA-384 hash algorithm
RS512RSASSA using SHA-512 hash algorithm
PS256RSASSA-PSS using SHA-256 hash algorithm
PS384RSASSA-PSS using SHA-384 hash algorithm
PS512RSASSA-PSS using SHA-512 hash algorithm
ES256ECDSA using P-256 curve and SHA-256 hash algorithm
ES384ECDSA using P-384 curve and SHA-384 hash algorithm
ES512ECDSA using P-521 curve and SHA-512 hash algorithm
noneNo digital signature or MAC value included

jws.sign(options)

(Synchronous) Return a JSON Web Signature for a header and a payload.

Options:

  • header
  • payload
  • secret or privateKey
  • encoding (Optional, defaults to 'utf8')

header must be an object with an alg property. header.alg must be one a value found in jws.ALGORITHMS. See above for a table of supported algorithms.

If payload is not a buffer or a string, it will be coerced into a string using JSON.stringify.

Example

const signature = jws.sign({
  header: { alg: 'HS256' },
  payload: 'h. jon benjamin',
  secret: 'has a van',
});

jws.verify(signature, algorithm, secretOrKey)

(Synchronous) Returns true or false for whether a signature matches a secret or key.

signature is a JWS Signature. header.alg must be a value found in jws.ALGORITHMS. See above for a table of supported algorithms. secretOrKey is a string or buffer containing either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA.

Note that the "alg" value from the signature header is ignored.

jws.decode(signature)

(Synchronous) Returns the decoded header, decoded payload, and signature parts of the JWS Signature.

Returns an object with three properties, e.g.

{ header: { alg: 'HS256' },
  payload: 'h. jon benjamin',
  signature: 'YOWPewyGHKu4Y_0M_vtlEnNlqmFOclqp4Hy6hVHfFT4'
}

jws.createSign(options)

Returns a new SignStream object.

Options:

  • header (required)
  • payload
  • key || privateKey || secret
  • encoding (Optional, defaults to 'utf8')

Other than header, all options expect a string or a buffer when the value is known ahead of time, or a stream for convenience. key/privateKey/secret may also be an object when using an encrypted private key, see the crypto documentation.

Example:


// This...
jws.createSign({
  header: { alg: 'RS256' },
  privateKey: privateKeyStream,
  payload: payloadStream,
}).on('done', function(signature) {
  // ...
});

// is equivalent to this:
const signer = jws.createSign({
  header: { alg: 'RS256' },
});
privateKeyStream.pipe(signer.privateKey);
payloadStream.pipe(signer.payload);
signer.on('done', function(signature) {
  // ...
});

jws.createVerify(options)

Returns a new VerifyStream object.

Options:

  • signature
  • algorithm
  • key || publicKey || secret
  • encoding (Optional, defaults to 'utf8')

All options expect a string or a buffer when the value is known ahead of time, or a stream for convenience.

Example:


// This...
jws.createVerify({
  publicKey: pubKeyStream,
  signature: sigStream,
}).on('done', function(verified, obj) {
  // ...
});

// is equivilant to this:
const verifier = jws.createVerify();
pubKeyStream.pipe(verifier.publicKey);
sigStream.pipe(verifier.signature);
verifier.on('done', function(verified, obj) {
  // ...
});

Class: SignStream

A Readable Stream that emits a single data event (the calculated signature) when done.

Event: 'done'

function (signature) { }

signer.payload

A Writable Stream that expects the JWS payload. Do not use if you passed a payload option to the constructor.

Example:

payloadStream.pipe(signer.payload);

signer.secret
signer.key
signer.privateKey

A Writable Stream. Expects the JWS secret for HMAC, or the privateKey for ECDSA and RSA. Do not use if you passed a secret or key option to the constructor.

Example:

privateKeyStream.pipe(signer.privateKey);

Class: VerifyStream

This is a Readable Stream that emits a single data event, the result of whether or not that signature was valid.

Event: 'done'

function (valid, obj) { }

valid is a boolean for whether or not the signature is valid.

verifier.signature

A Writable Stream that expects a JWS Signature. Do not use if you passed a signature option to the constructor.

verifier.secret
verifier.key
verifier.publicKey

A Writable Stream that expects a public key or secret. Do not use if you passed a key or secret option to the constructor.

TODO

  • It feels like there should be some convenience options/APIs for defining the algorithm rather than having to define a header object with { alg: 'ES512' } or whatever every time.

  • X.509 support, ugh

License

MIT

Copyright (c) 2013-2015 Brian J. Brennan

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.