crypto-js, jose, jsonwebtoken, jws, and node-jose are JavaScript libraries used for cryptographic operations and JSON Web Token (JWT) handling. crypto-js provides general-purpose cryptographic functions like AES, SHA, and HMAC but does not natively support JWT standards. jsonwebtoken is a high-level library focused on creating and verifying JWTs, primarily in Node.js environments. jws implements the lower-level JSON Web Signature (JWS) specification, handling only the signing and verification of tokens without claim validation. jose is a modern, standards-compliant implementation of the full JOSE suite (including JWT, JWS, JWE, and JWK) that works seamlessly in both browser and Node.js environments. node-jose was a previous JOSE implementation for Node.js but has been officially deprecated and should not be used in new projects.
When building modern web applications that require authentication, secure data exchange, or cryptographic operations, choosing the right library is critical. The packages crypto-js, jose, jsonwebtoken, jws, and node-jose all operate in this space — but they serve different purposes, target different environments, and follow different standards. Let’s cut through the confusion with a clear, practical comparison.
crypto-js is a general-purpose cryptographic library. It implements common algorithms like AES, SHA-256, HMAC, and PBKDF2. It does not handle JWTs natively — you’d need to manually encode/decode and sign tokens using its primitives.
// crypto-js: manual JWT-like token creation (not recommended for real JWTs)
import CryptoJS from 'crypto-js';
const header = CryptoJS.enc.Utf8.parse(JSON.stringify({ alg: 'HS256', typ: 'JWT' }));
const payload = CryptoJS.enc.Utf8.parse(JSON.stringify({ sub: '123', exp: 1735689600 }));
const encodedHeader = header.toString(CryptoJS.enc.Base64).replace(/=/g, '');
const encodedPayload = payload.toString(CryptoJS.enc.Base64).replace(/=/g, '');
const signature = CryptoJS.HmacSHA256(`${encodedHeader}.${encodedPayload}`, 'secret');
const jwt = `${encodedHeader}.${encodedPayload}.${signature.toString(CryptoJS.enc.Base64)}`;
jsonwebtoken is a high-level, widely used library for creating and verifying JSON Web Tokens (JWTs) using symmetric (HMAC) or asymmetric (RSA) keys. It’s designed primarily for Node.js but can be bundled for frontend use.
// jsonwebtoken: sign and verify a JWT
import jwt from 'jsonwebtoken';
const token = jwt.sign({ sub: '123' }, 'secret', { algorithm: 'HS256' });
const decoded = jwt.verify(token, 'secret');
jws is a lower-level library that implements the JSON Web Signature (JWS) specification — the core signing mechanism behind JWTs. It doesn’t handle claims validation (like expiration) — just signing and verification.
// jws: sign and verify a JWS (raw signature)
import jws from 'jws';
const sig = jws.sign({
header: { alg: 'HS256' },
payload: { sub: '123' },
secret: 'secret'
});
const isValid = jws.verify(sig, 'HS256', 'secret');
jose is a modern, standards-compliant implementation of JOSE (JSON Object Signing and Encryption) specifications, including JWS, JWE, JWT, and JWK. It supports both browser and Node.js, uses Web Crypto APIs when available, and emphasizes security best practices.
// jose: sign and verify a JWT
import { SignJWT, jwtVerify } from 'jose';
const secret = new TextEncoder().encode('secret');
const token = await new SignJWT({ sub: '123' })
.setProtectedHeader({ alg: 'HS256' })
.setIssuedAt()
.setExpirationTime('1h')
.sign(secret);
const { payload } = await jwtVerify(token, secret);
node-jose was a popular JOSE implementation for Node.js, but it has been officially deprecated as of 2021. Its GitHub repository states: “This library is no longer maintained. Please migrate to jose.” Do not use it in new projects.
⚠️ Deprecation Notice:
node-joseis deprecated. Avoid it entirely. Usejoseinstead.
crypto-js: Works in both browser and Node.js. Pure JavaScript, no native dependencies.jsonwebtoken: Designed for Node.js but can be bundled for browsers (though not officially optimized for it).jws: Also Node.js–first, but can run in browsers via bundlers.jose: Built for both environments. Uses Web Crypto in browsers and Node.js’s crypto module under the hood. Tree-shakable and modular.node-jose: Node.js only — and deprecated.If you’re building a frontend-only app (e.g., SPA that validates tokens issued by a backend), jose is the safest, most future-proof choice.
jose stands out for its support of JWK (JSON Web Keys) and modern key formats:
// jose: import a public key from PEM
import { importSPKI } from 'jose';
const publicKey = await importSPKI(pemKey, 'RS256');
const { payload } = await jwtVerify(token, publicKey);
In contrast, jsonwebtoken and jws expect raw strings or buffers for secrets/keys, making key rotation and format handling more manual.
crypto-js only supports symmetric cryptography (no RSA/ECDSA), so it cannot verify standard asymmetric JWTs used in OAuth/OpenID flows.
jose enforces strict validation by default (e.g., requires explicit algorithm declaration, rejects none alg).jsonwebtoken allows disabling validation (e.g., ignoreExpiration: true), which can lead to insecure usage if misconfigured.jws provides minimal abstraction — you must validate claims yourself.crypto-js gives you full control but no JWT-specific safeguards — easy to implement insecure token schemes.For production systems, especially those handling user authentication, jose’s opinionated, spec-compliant approach reduces the risk of common JWT pitfalls (like algorithm confusion).
You receive a JWT from an OAuth provider and need to verify its signature and claims in the browser.
jose// Using jose in a React component
import { jwtVerify } from 'jose';
async function verifyToken(token, jwk) {
const publicKey = await jose.importJWK(jwk, 'RS256');
return await jwtVerify(token, publicKey, {
issuer: 'https://your-domain.auth0.com/',
audience: 'your-audience'
});
}
You control both issuance and verification in a Node.js backend.
jsonwebtoken// Next.js API route
import jwt from 'jsonwebtoken';
export default function handler(req, res) {
const token = jwt.sign({ userId: req.user.id }, process.env.JWT_SECRET, {
expiresIn: '1h'
});
res.json({ token });
}
You need to encrypt user data before storing it in the browser.
crypto-jsjose supports JWE but is overkill; jsonwebtoken and jws don’t do encryption.// crypto-js for local encryption
import CryptoJS from 'crypto-js';
const encrypted = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret').toString();
const bytes = CryptoJS.AES.decrypt(encrypted, 'secret');
const decrypted = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
| Package | JWT Support | Browser Ready | Asymmetric Crypto | Deprecation Status | Best For |
|---|---|---|---|---|---|
crypto-js | ❌ (manual) | ✅ | ❌ | Active | General crypto (AES, SHA, HMAC) |
jose | ✅ (full) | ✅ | ✅ | Active | Modern, secure JWT/JWS/JWE in any environment |
jsonwebtoken | ✅ | ⚠️ (bundled) | ✅ | Active | Node.js backends with simple token needs |
jws | ✅ (JWS only) | ⚠️ (bundled) | ✅ | Active | Low-level JWS operations |
node-jose | ✅ | ❌ | ✅ | Deprecated | Do not use |
jose. It’s the only actively maintained, browser-friendly, standards-compliant library that handles JWTs securely and correctly.jsonwebtoken is acceptable if you’re already using it, but consider migrating to jose for better security defaults.node-jose completely — it’s deprecated and unmaintained.crypto-js only for non-JWT cryptographic tasks, like encrypting local data.In short: jose is the future. It’s built for the modern web, respects standards, and keeps you out of trouble.
Choose crypto-js if you need general-purpose cryptographic utilities like AES encryption, SHA hashing, or HMAC signing in the browser or Node.js, and you are not working with JWTs. It’s useful for encrypting local data or implementing custom security protocols, but avoid it for JWT-related tasks since it lacks built-in support for token standards and validation.
Choose jose if you're building a modern application that requires secure, standards-compliant JWT handling in either the browser or Node.js. It supports the full JOSE suite (JWT, JWS, JWE, JWK), uses platform-native crypto APIs, enforces secure defaults, and is actively maintained. Ideal for validating ID tokens from OAuth providers or implementing secure token-based auth in SPAs.
Choose jsonwebtoken if you're working in a Node.js backend environment and need a simple, high-level API for issuing and verifying symmetric (HMAC) or asymmetric (RSA) JWTs. It’s widely adopted and sufficient for basic token use cases, but be cautious about its permissive defaults and limited browser optimization.
Choose jws if you need low-level control over JSON Web Signatures without automatic claim validation (like expiration or issuer checks). It’s suitable for specialized scenarios where you’re implementing custom token logic or integrating with systems that only require raw JWS operations, but you’ll need to handle all validation manually.
Do not choose node-jose for any new project. It has been officially deprecated since 2021, is no longer maintained, and lacks support for modern security practices. Migrate existing implementations to jose, which is its recommended successor and offers better performance, security, and cross-environment compatibility.
JavaScript library of crypto standards.
Active development of CryptoJS has been discontinued. This library is no longer maintained.
Nowadays, NodeJS and modern browsers have a native Crypto module. The latest version of CryptoJS already uses the native Crypto module for random number generation, since Math.random() is not crypto-safe. Further development of CryptoJS would result in it only being a wrapper of native Crypto. Therefore, development and maintenance has been discontinued, it is time to go for the native crypto module.
Requirements:
npm install crypto-js
ES6 import for typical API call signing use case:
import sha256 from 'crypto-js/sha256';
import hmacSHA512 from 'crypto-js/hmac-sha512';
import Base64 from 'crypto-js/enc-base64';
const message, nonce, path, privateKey; // ...
const hashDigest = sha256(nonce + message);
const hmacDigest = Base64.stringify(hmacSHA512(path + hashDigest, privateKey));
Modular include:
var AES = require("crypto-js/aes");
var SHA256 = require("crypto-js/sha256");
...
console.log(SHA256("Message"));
Including all libraries, for access to extra methods:
var CryptoJS = require("crypto-js");
console.log(CryptoJS.HmacSHA1("Message", "Key"));
Requirements:
bower install crypto-js
Modular include:
require.config({
packages: [
{
name: 'crypto-js',
location: 'path-to/bower_components/crypto-js',
main: 'index'
}
]
});
require(["crypto-js/aes", "crypto-js/sha256"], function (AES, SHA256) {
console.log(SHA256("Message"));
});
Including all libraries, for access to extra methods:
// Above-mentioned will work or use this simple form
require.config({
paths: {
'crypto-js': 'path-to/bower_components/crypto-js/crypto-js'
}
});
require(["crypto-js"], function (CryptoJS) {
console.log(CryptoJS.HmacSHA1("Message", "Key"));
});
<script type="text/javascript" src="path-to/bower_components/crypto-js/crypto-js.js"></script>
<script type="text/javascript">
var encrypted = CryptoJS.AES(...);
var encrypted = CryptoJS.SHA256(...);
</script>
See: https://cryptojs.gitbook.io/docs/
var CryptoJS = require("crypto-js");
// Encrypt
var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123').toString();
// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var originalText = bytes.toString(CryptoJS.enc.Utf8);
console.log(originalText); // 'my message'
var CryptoJS = require("crypto-js");
var data = [{id: 1}, {id: 2}]
// Encrypt
var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123').toString();
// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
console.log(decryptedData); // [{id: 1}, {id: 2}]
crypto-js/corecrypto-js/x64-corecrypto-js/lib-typedarrayscrypto-js/md5crypto-js/sha1crypto-js/sha256crypto-js/sha224crypto-js/sha512crypto-js/sha384crypto-js/sha3crypto-js/ripemd160crypto-js/hmac-md5crypto-js/hmac-sha1crypto-js/hmac-sha256crypto-js/hmac-sha224crypto-js/hmac-sha512crypto-js/hmac-sha384crypto-js/hmac-sha3crypto-js/hmac-ripemd160crypto-js/pbkdf2crypto-js/aescrypto-js/tripledescrypto-js/rc4crypto-js/rabbitcrypto-js/rabbit-legacycrypto-js/evpkdfcrypto-js/format-opensslcrypto-js/format-hexcrypto-js/enc-latin1crypto-js/enc-utf8crypto-js/enc-hexcrypto-js/enc-utf16crypto-js/enc-base64crypto-js/mode-cfbcrypto-js/mode-ctrcrypto-js/mode-ctr-gladmancrypto-js/mode-ofbcrypto-js/mode-ecbcrypto-js/pad-pkcs7crypto-js/pad-ansix923crypto-js/pad-iso10126crypto-js/pad-iso97971crypto-js/pad-zeropaddingcrypto-js/pad-nopaddingChange default hash algorithm and iteration's for PBKDF2 to prevent weak security by using the default configuration.
Custom KDF Hasher
Blowfish support
Fix module order in bundled release.
Include the browser field in the released package.json.
Added url safe variant of base64 encoding. 357
Avoid webpack to add crypto-browser package. 364
This is an update including breaking changes for some environments.
In this version Math.random() has been replaced by the random methods of the native crypto module.
For this reason CryptoJS might not run in some JavaScript environments without native crypto module. Such as IE 10 or before or React Native.
Rollback, 3.3.0 is the same as 3.1.9-1.
The move of using native secure crypto module will be shifted to a new 4.x.x version. As it is a breaking change the impact is too big for a minor release.
The usage of the native crypto module has been fixed. The import and access of the native crypto module has been improved.
In this version Math.random() has been replaced by the random methods of the native crypto module.
For this reason CryptoJS might does not run in some JavaScript environments without native crypto module. Such as IE 10 or before.
If it's absolute required to run CryptoJS in such an environment, stay with 3.1.x version. Encrypting and decrypting stays compatible. But keep in mind 3.1.x versions still use Math.random() which is cryptographically not secure, as it's not random enough.
This version came along with CRITICAL BUG.
DO NOT USE THIS VERSION! Please, go for a newer version!
The 3.1.x are based on the original CryptoJS, wrapped in CommonJS modules.