JWE Encrypt & Decrypt Online | JSON Web Encryption RFC 7516
Encryption 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
| Algorithm | Key Type | Authenticated | Best for |
|---|---|---|---|
| dir | Shared secret | N/A | Simplest — both sides share the same key |
| RSA-OAEP-256 | RSA public key (PEM) | No | Asymmetric — send to a specific recipient |
| A128KW / A256KW | AES key (Base64URL) | No | Symmetric key wrapping |
| A128GCMKW / A256GCMKW | AES key (Base64URL) | Yes (GCM tag) | Authenticated key wrapping |
| PBES2-HS256+A128KW | Password | No | Password-based encryption |
| PBES2-HS512+A256KW | Password | No | Password-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
Security Notes
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
- RFC 7516 — JSON Web Encryption (JWE)
- RFC 7518 — JSON Web Algorithms (JWA)
- Auth0 — Encrypt JSON Web Tokens (JWEs)
- RFC 7515 — JSON Web Signature (JWS)
Related Concepts
- JWT Signature Verification — JWS (JSON Web Signature) is the signing counterpart to JWE
- AES-256 Encryption — The content encryption used inside JWE is typically AES-GCM
- RSA-OAEP Encryption — RSA key transport used in JWE's key management layer
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
AES Encrypt/Decrypt
Encrypt and decrypt with AES-128/192/256 online. GCM, CTR, and OpenSSL-compatible CBC modes. Passphrase or raw key, custom IV.
ChaCha20 / Salsa20 Encrypt/Decrypt
Encrypt and decrypt with ChaCha20, XChaCha20, ChaCha20-Poly1305 (AEAD), or Salsa20 online. Passphrase mode with PBKDF2 key derivation.
RSA Encrypt / Decrypt
Encrypt and decrypt with RSA-OAEP online via Web Crypto API. Built-in key generator, PKCS#8/PKCS#1 conversion, SHA-256/384/512.
DES Encrypt/Decrypt
Encrypt and decrypt with DES or 3DES (Triple DES) online. CBC/ECB/CFB/OFB modes, PKCS7/NoPadding, OpenSSL compatible.
XOR Encrypt/Decrypt
Encrypt and decrypt with XOR cipher online. Text/Hex/Base64 formats, visual XOR table, brute-force key breaking, auto-solve.
Blowfish Encrypt/Decrypt
Encrypt and decrypt with Blowfish online. 5 cipher modes, 5 paddings, GBK/UTF-16 support, OpenSSL passphrase compatible.
PGP Encrypt / Decrypt
Encrypt, decrypt, sign, and verify with OpenPGP online. Public key and password modes, built-in key generator, GnuPG compatible.