or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

compression.mdindex.mdjwk-support.mdjwt-building.mdjwt-parsing.mdsecurity-algorithms.mdutilities.md
tile.json

tessl/maven-io-jsonwebtoken--jjwt-impl

JJWT Implementation module providing concrete implementations of JSON Web Token (JWT) creation, parsing, verification, and cryptographic operations for Java and Android applications.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.jsonwebtoken/jjwt-impl@0.12.x

To install, run

npx @tessl/cli install tessl/maven-io-jsonwebtoken--jjwt-impl@0.12.0

index.mddocs/

JJWT Implementation Module

The JJWT Implementation module (io.jsonwebtoken:jjwt-impl) provides concrete implementations of JSON Web Token (JWT) creation, parsing, verification, and cryptographic operations for Java and Android applications. This module works in conjunction with the JJWT API module to deliver a complete JWT/JWS/JWE solution.

Package Information

PropertyValue
Package Nameio.jsonwebtoken:jjwt-impl
TypeMaven Dependency
LanguageJava
Version0.12.6
LicenseApache 2.0
JDK SupportJava 8+

Core Imports

Maven Dependency

<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-impl</artifactId>
    <version>0.12.6</version>
    <scope>runtime</scope>
</dependency>
<!-- Also include the API module -->
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-api</artifactId>
    <version>0.12.6</version>
</dependency>

Java Imports

// Core JWT Operations
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.JwtParser;

// Token Types
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwe;
import io.jsonwebtoken.Claims;

// Security
import io.jsonwebtoken.security.Keys;
import io.jsonwebtoken.security.SecureDigestAlgorithm;
import io.jsonwebtoken.security.AeadAlgorithm;
import io.jsonwebtoken.security.KeyAlgorithm;

// JWK Support
import io.jsonwebtoken.security.Jwk;
import io.jsonwebtoken.security.JwkSet;

// Standard Java
import javax.crypto.SecretKey;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Date;

Basic Usage

Creating JWTs

// Create a secret key for HMAC signing
SecretKey key = Jwts.SIG.HS256.key().build();

// Create a simple JWT with claims
String jwt = Jwts.builder()
    .subject("john.doe")
    .issuer("my-app")
    .issuedAt(new Date())
    .expiration(new Date(System.currentTimeMillis() + 3600000)) // 1 hour
    .signWith(key)
    .compact();

// Create a JWT with custom claims
String customJwt = Jwts.builder()
    .claims()
        .subject("user123")
        .add("role", "admin")
        .add("permissions", Arrays.asList("read", "write"))
        .and()
    .signWith(key)
    .compact();

Parsing JWTs

// Parse and verify a signed JWT
JwtParser parser = Jwts.parser()
    .verifyWith(key)
    .build();

Jws<Claims> jws = parser.parseSignedClaims(jwt);
Claims claims = jws.getPayload();

String subject = claims.getSubject();
String issuer = claims.getIssuer();
Date expiration = claims.getExpiration();

// Access custom claims
String role = claims.get("role", String.class);
List<String> permissions = claims.get("permissions", List.class);

Algorithm Usage

// Use different signature algorithms
SecretKey hmacKey = Jwts.SIG.HS512.key().build();
KeyPair rsaKeyPair = Jwts.SIG.RS256.keyPair().build();
KeyPair ecKeyPair = Jwts.SIG.ES256.keyPair().build();

// Create JWS with different algorithms
String hmacJwt = Jwts.builder()
    .subject("user")
    .signWith(hmacKey, Jwts.SIG.HS512)
    .compact();

String rsaJwt = Jwts.builder()
    .subject("user")
    .signWith(rsaKeyPair.getPrivate(), Jwts.SIG.RS256)
    .compact();

// Parse with corresponding verification keys
Jws<Claims> hmacClaims = Jwts.parser()
    .verifyWith(hmacKey)
    .build()
    .parseSignedClaims(hmacJwt);

Jws<Claims> rsaClaims = Jwts.parser()
    .verifyWith(rsaKeyPair.getPublic())
    .build()
    .parseSignedClaims(rsaJwt);

Architecture

The JJWT Implementation module is organized into several key packages:

Core Implementation (io.jsonwebtoken.impl)

  • DefaultJwtBuilder: Main JWT/JWS/JWE creation factory
  • DefaultJwtParserBuilder: Parser configuration factory
  • DefaultJwtParser: JWT/JWS/JWE parsing engine
  • Token Models: DefaultJwt, DefaultJws, DefaultJwe implementations
  • Header/Claims Builders: Type-safe construction utilities

Security Package (io.jsonwebtoken.impl.security)

  • Algorithm Registries: Signature, encryption, key management algorithms
  • JWK Implementation: JSON Web Key parsing, building, operations
  • Key Generation: Symmetric and asymmetric key creation utilities
  • Cryptographic Support: JCA provider abstractions and security utilities

Compression Package (io.jsonwebtoken.impl.compression)

  • DEFLATE Algorithm: RFC 1951 standard compression
  • GZIP Algorithm: Common extension compression format
  • Abstract Base: Extensible compression algorithm framework

I/O and Utilities

  • Base64URL Codec: RFC 4648 compliant encoding/decoding
  • Stream Processing: Memory-efficient payload handling
  • Service Discovery: Plugin architecture support
  • Parameter Validation: Type-safe configuration utilities

Capabilities

JWT Building

Comprehensive JWT, JWS, and JWE token creation with the DefaultJwtBuilder class.

// Quick example - full JWT creation with encryption
SecretKey encKey = Jwts.ENC.A256GCM.key().build();
SecretKey kekKey = Jwts.KEY.A256KW.key().build();

String jwe = Jwts.builder()
    .subject("sensitive-user")
    .claim("ssn", "123-45-6789")
    .encryptWith(kekKey, Jwts.KEY.A256KW, Jwts.ENC.A256GCM)
    .compact();

JWT Parsing

Flexible JWT, JWS, and JWE token parsing and validation with DefaultJwtParser.

// Quick example - parsing with clock skew tolerance
JwtParser parser = Jwts.parser()
    .decryptWith(kekKey)
    .clockSkewSeconds(30) // Allow 30 seconds clock skew
    .build();

Jwe<Claims> jwe = parser.parseEncryptedClaims(encryptedJwt);

Security Algorithms

Complete JWA-compliant algorithm implementations for signatures, encryption, and key management.

// Quick example - algorithm discovery and key generation
SecureDigestAlgorithm<?, ?> signAlg = Jwts.SIG.get().forKey(someKey);
SecretKey newKey = signAlg.key().build();

JWK Support

Full JSON Web Key (JWK) and JWK Set functionality with RFC 7517 compliance.

// Quick example - JWK creation and parsing
Jwk<SecretKey> jwk = Jwts.JWK.builder(secretKey)
    .id("my-key-1")
    .operations().add("sign").add("verify").and()
    .build();

String jwkJson = jwk.toJson();

Compression

Payload compression support with DEFLATE and GZIP algorithms.

// Quick example - compressed JWT
String compressed = Jwts.builder()
    .subject("user")
    .claim("data", largeDataString)
    .compressWith(Jwts.ZIP.DEF)
    .signWith(key)
    .compact();

Utilities

Essential utilities including cryptographic key management, Base64URL encoding, stream processing, and service discovery.

// Quick example - secure key generation
SecretKey hmacKey = Keys.hmacShaKeyFor(secureRandomBytes);
Password password = Keys.password("secret".toCharArray());

// Base64URL operations
Base64UrlCodec codec = new Base64UrlCodec();
String encoded = codec.encode("Hello World");
byte[] decoded = codec.decode(encoded);

Implementation Features

Key Characteristics

  • Production Ready: Battle-tested implementation used by thousands of applications
  • JCA Integration: Full Java Cryptography Architecture support with provider flexibility
  • Memory Efficient: Stream-based processing for large payloads
  • Extensible: Service provider interface for custom algorithms and components
  • Type Safe: Generic type system prevents runtime class cast exceptions
  • Secure by Default: Automatic key validation and algorithm selection

Performance Optimizations

  • Algorithm Registries: Fast O(1) algorithm lookup by identifier
  • Service Caching: Cached service discovery with lazy initialization
  • Stream Processing: Avoids loading entire payloads into memory
  • Base64URL: Optimized encoding/decoding without intermediate String creation

Security Features

  • Key Strength Validation: Automatic validation of key lengths per algorithm
  • Critical Header Parameters: Validation of critical extension parameters
  • Clock Skew Tolerance: Configurable time-based claim validation
  • JCA Provider Support: Pluggable cryptographic provider architecture

This implementation module provides the complete runtime functionality for JWT operations while maintaining clean separation from the API definitions, enabling flexible deployment and testing scenarios.