JWE Encrypt & Decrypt Online | JSON Web Encryption RFC 7516

Encryption
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.
⚠️ Critical Security: JWE compact serialization is large — tokens can be 200+ bytes even for small payloads. Use AES-256-GCM for bulk data encryption. JWE is best suited for encrypting small JSON payloads (JWT claims, API keys, session tokens) where interoperability with web services is needed.

How It Works

What Is JWE (JSON Web Encryption)?

JWE (JSON Web Encryption), defined in RFC 7516, is a standard for encrypting JSON data into a compact token with 5 Base64URL-encoded parts: header.encryptedKey.iv.ciphertext.tag. It separates key management (how the encryption key is protected) from content encryption (how the data is actually encrypted), allowing flexible combinations like RSA-OAEP-256 wrapping an AES-GCM content key.

This tool supports multiple key management algorithms — direct key (dir), RSA-OAEP-256, AES key wrap (A128KW/A256KW), AES-GCM key wrap (A128GCMKW/A256GCMKW), and PBES2 password-based encryption. Content encryption uses A128GCM, A256GCM, A128CBC-HS256, or A256CBC-HS512. All operations run locally in your browser via the Web Crypto API.

When to Use JWE

  • API token encryption — Securely transmit JSON payloads (JWT claims, session data) between services
  • Password-based encryption — PBES2 allows encrypting with a shared password instead of pre-shared keys
  • Asymmetric encryption for web services — RSA-OAEP-256 lets you encrypt a CEK for a specific recipient's public key
  • JWT with confidentiality — Combine with JWT to create encrypted tokens that hide claims from intermediaries
  • Cross-platform interoperability — JWE is a web standard supported by libraries in every major language
  • When NOT to use — For large file encryption, use AES-256-GCM directly; JWE adds significant overhead

Key Management Algorithms

AlgorithmKey TypeAuthenticatedBest for
dirShared secretN/ASimplest — both sides share the same key
RSA-OAEP-256RSA public key (PEM)NoAsymmetric — send to a specific recipient
A128KW / A256KWAES key (Base64URL)NoSymmetric key wrapping
A128GCMKW / A256GCMKWAES key (Base64URL)Yes (GCM tag)Authenticated key wrapping
PBES2-HS256+A128KWPasswordNoPassword-based encryption
PBES2-HS512+A256KWPasswordNoPassword-based, stronger derivation

Standards Compliance

  • RFC 7516 — JSON Web Encryption (JWE) specification
  • RFC 7518 — JSON Web Algorithms (JWA) — defines algorithm parameters
  • RFC 7515 — JSON Web Signature (JWS) — often used alongside JWE
  • NIST SP 800-56B — RSA-OAEP key transport recommendation
  • Web Crypto API — W3C standard for browser-based cryptography

Last updated:

Code Examples

Create and decrypt JWE tokens in multiple languages:

JavaScript — Browser (jose library)

// JWE with dir + A256GCM
import { CompactEncrypt, compactDecrypt } from 'jose';

const key = new TextEncoder().encode('your-32-byte-shared-secret!!');
const payload = new TextEncoder().encode(JSON.stringify({ sub: 'user123' }));

const jwe = await new CompactEncrypt(payload)
  .setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
  .encrypt(key);
console.log('JWE token:', jwe);

// Decrypt
const { plaintext } = await compactDecrypt(jwe, key);
console.log('Payload:', JSON.parse(new TextDecoder().decode(plaintext)));

Python — authlib

from authlib.jose import JsonWebEncryption

jwe = JsonWebEncryption()
header = {'alg': 'dir', 'enc': 'A256GCM'}
payload = b'{"sub": "user123"}'
key = b'your-32-byte-shared-secret!!'

token = jwe.serialize_compact(header, payload, key)
print('JWE:', token.decode())

# Decrypt
result = jwe.deserialize_compact(token, key)
print('Payload:', result['payload'])

Go — go-jose

import "github.com/go-jose/go-jose/v4"

key := []byte("your-32-byte-shared-secret!!")

opts := &jose.EncrypterOptions{
    Algorithm: jose.DIRECT,
    ExtraHeaders: map[jose.HeaderKey]interface{}{
        jose.HeaderType: "JWT",
    },
}
enc, _ := jose.NewEncrypter(jose.A256GCM, opts, key)
payload := []byte({"sub":"user123"})
jwe, _ := enc.Encrypt(payload)
fmt.Println(jwe.CompactSerialize())

Rust — jose-jwe

// Rust JWE support is limited; consider using a wrapper library
// or implementing via the jsonwebtoken crate for JWT + JWE
use jose_jwe::{Header, ContentEncryptionAlgorithm};

let key = b"your-32-byte-shared-secret!!";
let header = Header {
    alg: jose_jwa::KeyManagementAlgorithm::Direct,
    enc: ContentEncryptionAlgorithm::A256Gcm,
    ..Default::default()
};
// Encrypt payload with header and key

Node.js — jose (CommonJS)

const { CompactEncrypt, compactDecrypt } = require('jose');

async function encryptJWE(payload, secret) {
  const key = new TextEncoder().encode(secret);
  const data = new TextEncoder().encode(JSON.stringify(payload));
  return new CompactEncrypt(data)
    .setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
    .encrypt(key);
}

encryptJWE({ sub: 'user123' }, 'your-32-byte-shared-secret!!')
  .then(jwe => console.log('JWE:', jwe));

Common Pitfalls

⚠️ Using RSA1_5 (PKCS#1 v1.5) Key Transport: RSA1_5 is vulnerable to padding oracle attacks (Bleichenbacher). Always use RSA-OAEP-256 for asymmetric key transport. RSA1_5 is included in JWE libraries for backward compatibility only.
⚠️ Weak Passwords with PBES2: PBES2 derives the key wrapping key from a password using PBKDF2. A weak password (low entropy) makes the entire JWE vulnerable to dictionary attacks, regardless of the content encryption algorithm. Use high-entropy passphrases.
⚠️ JWE Tokens Are Large: A JWE with RSA-OAEP-256 + A256GCM is typically 300–500 bytes even for a tiny payload. Don't put JWE in URL query strings — use POST body or Authorization headers instead.
⚠️ Confusing JWE with JWS: JWE encrypts data (confidentiality); JWS signs data (integrity/authenticity). They are separate standards. For both, use nested JWE+JWS or the "encrypt-then-sign" pattern.
⚠️ Not Validating the "alg" Header: When decrypting received JWEs, always validate the algorithm header matches your expected algorithm. Accepting unexpected algorithmss can lead to algorithm confusion attacks.

Security Notes

ℹ️ Prefer GCM Content Encryption: A256GCM provides authenticated encryption (AEAD) — it protects both confidentiality and integrity. CBC variants require separate HMAC verification and are more complex to use securely.
ℹ️ Use A256GCMKW for Authenticated Key Wrapping: When using symmetric key wrapping, prefer A256GCMKW over A256KW — GCMKW provides authentication of the wrapped key, preventing tampering.
ℹ️ Key Size Requirements: For "dir" with A256GCM, the shared secret must be exactly 32 bytes. For A128GCM, it must be 16 bytes. The tool validates key sizes automatically.
ℹ️ JWE Compact vs JSON Serialization: This tool uses compact serialization (5 dot-separated parts). JSON serialization (RFC 7516 §7.2) supports multiple recipients but is not widely used in web APIs.

Disclaimer

This tool is provided for educational and development purposes. JWE implementation correctness varies across libraries — always validate interoperability with your target platform. For production systems, use well-audited libraries (jose, authlib, go-jose) and follow RFC 7516 / RFC 7518 specifications.

Further Reading

Related Concepts

Related Tools

Need to verify a JWT signature instead? Try the JWT Signature Verifier. For generating RSA key pairs used with RSA-OAEP-256, the RSA Key Generator creates keys in PEM format. For symmetric encryption of large payloads, try the AES Encrypt/Decrypt tool.

Frequently Asked Questions

Which key management algorithm should I choose?

Use "dir" (direct key) when both sides share a secret — simplest and fastest. Use "RSA-OAEP-256" when the recipient has an RSA key pair — the CEK is generated randomly and wrapped with RSA. Use "A128KW" or "A256KW" for AES key wrapping with a pre-shared key encryption key. Use "A128GCMKW" or "A256GCMKW" for authenticated key wrapping (AES-GCM). Use "PBES2-HS256+A128KW" or "PBES2-HS512+A256KW" when you want to encrypt with a password instead of a pre-shared key — the wrapping key is derived via PBKDF2.

Which content encryption algorithm should I use?

A256GCM is recommended for most cases — it provides authenticated encryption with a 256-bit key. A128GCM is faster with slightly lower security margin. A128CBC-HS256 and A256CBC-HS512 are legacy options for compatibility with systems that don't support GCM.

What key format do I need for each algorithm?

For "dir", enter the shared secret directly. For "RSA-OAEP-256", paste the recipient's RSA public key in PEM format. For AES key wrap algorithms (A128KW/A256KW/GCMKW), enter the key in Base64URL format. For PBES2, enter any password — the wrapping key is derived automatically.

Is the encryption done client-side?

Yes. All encryption and decryption happens locally in your browser using the Web Crypto API. No data, keys, or tokens are sent to any server.

Can I decrypt a JWE from another library?

Yes, as long as the JWE uses compact serialization and standard algorithms (dir, RSA-OAEP-256, A128/256KW, A128/256GCMKW, PBES2). Paste the full 5-part JWE token into the Decrypt mode and provide the matching key.

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Encryption

Learn More