jws vs jsonwebtoken vs jose vs crypto-js vs node-jose
JavaScript Cryptography and JWT Libraries Comparison
1 Year
jwsjsonwebtokenjosecrypto-jsnode-joseSimilar Packages:
What's JavaScript Cryptography and JWT Libraries?

These libraries provide various cryptographic functionalities and JSON Web Token (JWT) handling capabilities for web applications. They are essential for securing data transmission, authentication, and authorization processes in modern web development. Each library offers unique features and approaches to cryptography, making them suitable for different scenarios and requirements in web applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
jws29,122,160715-285 years agoMIT
jsonwebtoken18,619,09417,86743.5 kB1712 years agoMIT
jose14,151,3606,143247 kB03 days agoMIT
crypto-js8,457,21716,016487 kB274a year agoMIT
node-jose1,042,452709353 kB662 years agoApache-2.0
Feature Comparison: jws vs jsonwebtoken vs jose vs crypto-js vs node-jose

Cryptographic Functions

  • jws:

    JWS specializes in creating and verifying JSON Web Signatures, ensuring the integrity and authenticity of data. It provides a minimalistic approach to signing data, making it easy to integrate into applications that require data integrity checks.

  • jsonwebtoken:

    jsonwebtoken focuses primarily on JWT creation and verification, providing a simple API to encode and decode tokens. It supports various signing algorithms, making it a straightforward choice for applications needing basic JWT functionality.

  • jose:

    JOSE provides a full suite of cryptographic operations, including signing, verification, encryption, and decryption of JWTs. It supports multiple algorithms and is compliant with the latest security standards, making it ideal for secure token handling.

  • crypto-js:

    Crypto-JS offers a variety of cryptographic functions including AES encryption, SHA hashing, HMAC, and more. It is designed for simplicity and performance, making it suitable for applications that require basic encryption and hashing without complex configurations.

  • node-jose:

    node-jose is a comprehensive library that supports both JWS and JWE, allowing for advanced cryptographic operations including key management and encryption. It is designed for applications that require robust security features and flexibility.

Standards Compliance

  • jws:

    JWS follows the JSON Web Signature specification, ensuring that signed data can be verified according to established standards. It is suitable for applications that need to ensure data integrity through signatures.

  • jsonwebtoken:

    jsonwebtoken is primarily focused on JWT standards, ensuring that tokens are created and verified according to the JWT specification. It is a reliable choice for applications that need to implement token-based authentication.

  • jose:

    JOSE is built around the JSON Object Signing and Encryption standards, ensuring compliance with modern security protocols. It is ideal for applications that require adherence to standards such as OAuth2 and OpenID Connect.

  • crypto-js:

    Crypto-JS does not strictly adhere to any specific cryptographic standards but implements common algorithms widely used in the industry. It is suitable for general-purpose cryptography but may not meet all compliance requirements for sensitive applications.

  • node-jose:

    node-jose complies with both JWS and JWE standards, providing a robust framework for secure data handling. It is ideal for applications that require adherence to cryptographic standards for security.

Ease of Use

  • jws:

    JWS offers a straightforward approach to signing and verifying data, making it easy to implement in applications that require data integrity. Its minimalistic design allows for quick integration without unnecessary complexity.

  • jsonwebtoken:

    jsonwebtoken is designed for ease of use, with a simple API that allows developers to quickly create and verify JWTs. It is well-documented and widely used, making it a go-to choice for many developers.

  • jose:

    JOSE has a more complex API due to its comprehensive feature set, but it provides detailed documentation and examples to help developers implement secure token handling effectively. It may require a bit more time to learn compared to simpler libraries.

  • crypto-js:

    Crypto-JS is known for its simplicity and ease of use, making it accessible for developers who need basic cryptographic functions without a steep learning curve. Its straightforward API allows for quick integration into projects.

  • node-jose:

    node-jose has a steeper learning curve due to its advanced features and capabilities. However, it provides extensive documentation and examples, making it easier for developers to understand and utilize its full potential.

Performance

  • jws:

    JWS is lightweight and optimized for performance, ensuring that signing and verifying operations are fast and efficient. It is suitable for applications that require quick integrity checks without compromising security.

  • jsonwebtoken:

    jsonwebtoken is efficient for creating and verifying JWTs, with performance suitable for most applications. It is designed to handle token operations quickly, making it a practical choice for applications with moderate security needs.

  • jose:

    JOSE is designed for secure operations, which may introduce some performance overhead compared to simpler libraries. However, it is optimized for handling JWTs efficiently, making it suitable for applications that prioritize security over raw speed.

  • crypto-js:

    Crypto-JS is optimized for performance, providing fast cryptographic operations suitable for client-side applications. Its lightweight nature ensures minimal impact on application performance, making it ideal for scenarios where speed is crucial.

  • node-jose:

    node-jose may have a performance overhead due to its comprehensive features, but it is optimized for secure operations. It is suitable for applications that require advanced cryptographic capabilities while maintaining reasonable performance.

Community Support

  • jws:

    JWS has a smaller community compared to others but is still actively maintained. It provides sufficient documentation and examples for developers to implement it in their applications effectively.

  • jsonwebtoken:

    jsonwebtoken is one of the most popular libraries for JWT handling, with a large community and extensive resources available. It is well-supported, making it a reliable choice for developers.

  • jose:

    JOSE is actively maintained and has a growing community, providing support and updates to keep up with security standards. Its documentation and examples help developers implement it effectively in their projects.

  • crypto-js:

    Crypto-JS has a strong community and is widely used in various applications, ensuring good support and resources for developers. Its popularity means that many issues have been addressed through community contributions.

  • node-jose:

    node-jose has a dedicated community and is actively maintained, providing good support and resources for developers. Its comprehensive features attract a niche audience looking for advanced cryptographic capabilities.

How to Choose: jws vs jsonwebtoken vs jose vs crypto-js vs node-jose
  • jws:

    Use JWS if your focus is specifically on creating and verifying JSON Web Signature (JWS) tokens. It provides a lightweight solution for signing and verifying data, which is essential for ensuring data integrity and authenticity in web applications.

  • jsonwebtoken:

    Opt for jsonwebtoken if you need a straightforward solution for creating and verifying JWTs. It is widely used and has a simple API, making it a good choice for applications that require basic token management without the overhead of additional features.

  • jose:

    Select JOSE if you require a comprehensive library for handling JSON Web Tokens (JWT), JWS, and JWE. It adheres to the latest standards and provides a robust set of features for secure token creation and verification, making it ideal for applications that need to implement OAuth2 or OpenID Connect.

  • crypto-js:

    Choose Crypto-JS if you need a lightweight library for basic cryptographic operations such as hashing, encryption, and decryption. It is easy to use and integrates well with existing JavaScript applications without any dependencies.

  • node-jose:

    Choose node-jose if you need a powerful library that supports both JWS and JWE, along with advanced features like key management and encryption. It is suitable for applications that require a high level of security and flexibility in handling 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 Value | Digital Signature or MAC Algorithm ----------------|---------------------------- HS256 | HMAC using SHA-256 hash algorithm HS384 | HMAC using SHA-384 hash algorithm HS512 | HMAC using SHA-512 hash algorithm RS256 | RSASSA using SHA-256 hash algorithm RS384 | RSASSA using SHA-384 hash algorithm RS512 | RSASSA using SHA-512 hash algorithm PS256 | RSASSA-PSS using SHA-256 hash algorithm PS384 | RSASSA-PSS using SHA-384 hash algorithm PS512 | RSASSA-PSS using SHA-512 hash algorithm ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm none | No 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.