Java JWT: JSON Web Token for Java and Android
:doctype: book = Java JWT: JSON Web Token for Java and Android :project-version: 0.13.0 :toc: :toc-title: :toc-placement!: :toclevels: 4
ifdef::env-github[] :tip-caption: ✏️TIP :note-caption: ℹ️ NOTE :important-caption: ‼️IMPORTANT :caution-caption: ⛔️CAUTION :warning-caption: ⚠️WARNING endif::[]
// Macros :fn-require-java11-plus: Requires Java 11 or a compatible JCA Provider (like BouncyCastle) in the runtime classpath. :fn-require-java15-plus: Requires Java 15 or a compatible JCA Provider (like BouncyCastle) in the runtime classpath.
image:https://github.com/jwtk/jjwt/actions/workflows/ci.yml/badge.svg?branch=master[Build Status,link=https://github.com/jwtk/jjwt/actions/workflows/ci.yml?query=branch%3Amaster] image:https://coveralls.io/repos/github/jwtk/jjwt/badge.svg?branch=master[Coverage Status,link=https://coveralls.io/github/jwtk/jjwt?branch=master] image:https://snyk-widget.herokuapp.com/badge/mvn/io.jsonwebtoken/jjwt-root/badge.svg[Vuln score,link=https://snyk-widget.herokuapp.com/badge/mvn/io.jsonwebtoken/jjwt-root/badge.svg] image:https://snyk.io/test/github/jwtk/jjwt/badge.svg[Known Vulns,link=https://snyk.io/test/github/jwtk/jjwt/badge.svg] image:https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A[link="https://community.develocity.cloud/scans?search.rootProjectNames=JJWT",title="Revved up by Develocity"]
JJWT aims to be the easiest to use and understand library for creating and verifying JSON Web Tokens (JWTs) and JSON Web Keys (JWKs) on the JVM and Android.
JJWT is a pure Java implementation based exclusively on the https://datatracker.ietf.org/wg/jose/documents/[JOSE Working Group] RFC specifications:
It was created by https://github.com/lhazlewood[Les Hazlewood] and is supported and maintained by a https://github.com/jwtk/jjwt/graphs/contributors[community] of contributors.
JJWT is open source under the terms of the http://www.apache.org/licenses/LICENSE-2.0[Apache 2.0 License].
++++++++++++
== Features
|=== | Identifier | Signature Algorithm
| HS256
| HMAC using SHA-256
| HS384
| HMAC using SHA-384
| HS512
| HMAC using SHA-512
| ES256
| ECDSA using P-256 and SHA-256
| ES384
| ECDSA using P-384 and SHA-384
| ES512
| ECDSA using P-521 and SHA-512
| RS256
| RSASSA-PKCS-v1_5 using SHA-256
| RS384
| RSASSA-PKCS-v1_5 using SHA-384
| RS512
| RSASSA-PKCS-v1_5 using SHA-512
| PS256
| RSASSA-PSS using SHA-256 and MGF1 with SHA-256^1^
| PS384
| RSASSA-PSS using SHA-384 and MGF1 with SHA-384^1^
| PS512
| RSASSA-PSS using SHA-512 and MGF1 with SHA-512^1^
| EdDSA
| Edwards-curve Digital Signature Algorithm^2^
|===
+
^1.{sp}{fn-require-java11-plus}^
+
^2.{sp}{fn-require-java15-plus}^
|=== | Identifier | Encryption Algorithm
| A128CBC‑HS256
| https://www.rfc-editor.org/rfc/rfc7518.html#section-5.2.3[AES_128_CBC_HMAC_SHA_256] authenticated encryption algorithm
| A192CBC-HS384
| https://www.rfc-editor.org/rfc/rfc7518.html#section-5.2.4[AES_192_CBC_HMAC_SHA_384] authenticated encryption algorithm
| A256CBC-HS512
| https://www.rfc-editor.org/rfc/rfc7518.html#section-5.2.5[AES_256_CBC_HMAC_SHA_512] authenticated encryption algorithm
| A128GCM
| AES GCM using 128-bit key
| A192GCM
| AES GCM using 192-bit key
| A256GCM
| AES GCM using 256-bit key
|===
+
|=== | Identifier | Key Management Algorithm
| RSA1_5
| RSAES-PKCS1-v1_5
| RSA-OAEP
| RSAES OAEP using default parameters
| RSA-OAEP-256
| RSAES OAEP using SHA-256 and MGF1 with SHA-256
| A128KW
| AES Key Wrap with default initial value using 128-bit key
| A192KW
| AES Key Wrap with default initial value using 192-bit key
| A256KW
| AES Key Wrap with default initial value using 256-bit key
| dir
| Direct use of a shared symmetric key as the CEK
| ECDH-ES
| Elliptic Curve Diffie-Hellman Ephemeral Static key agreement using Concat KDF
| ECDH-ES+A128KW
| ECDH-ES using Concat KDF and CEK wrapped with "A128KW"
| ECDH-ES+A192KW
| ECDH-ES using Concat KDF and CEK wrapped with "A192KW"
| ECDH-ES+A256KW
| ECDH-ES using Concat KDF and CEK wrapped with "A256KW"
| A128GCMKW
| Key wrapping with AES GCM using 128-bit key
| A192GCMKW
| Key wrapping with AES GCM using 192-bit key
| A256GCMKW
| Key wrapping with AES GCM using 256-bit key
| PBES2-HS256+A128KW
| PBES2 with HMAC SHA-256 and "A128KW" wrapping
| PBES2-HS384+A192KW
| PBES2 with HMAC SHA-384 and "A192KW" wrapping
| PBES2‑HS512+A256KW
| PBES2 with HMAC SHA-512 and "A256KW" wrapping
|===
+
Key types:|===
| JWK Key Format | Java Key Type | JJWT Jwk Type
| Symmetric Key
| SecretKey
| SecretJwk
| Elliptic Curve Public Key
| ECPublicKey
| EcPublicJwk
| Elliptic Curve Private Key
| ECPrivateKey
| EcPrivateJwk
| RSA Public Key
| RSAPublicKey
| RsaPublicJwk
| RSA Private Key
| RSAPrivateKey
| RsaPrivateJwk
| XDH Public Key
| XECPublicKey^1^
| OctetPublicJwk
| XDH Private Key
| XECPrivateKey^1^
| OctetPrivateJwk
| EdDSA Public Key
| EdECPublicKey^2^
| OctetPublicJwk
| EdDSA Private Key
| EdECPrivateKey^2^
| OctetPrivateJwk
|===
+
^1.{sp}{fn-require-java15-plus}^
+
^2.{sp}{fn-require-java15-plus}^
++++++++++++
=== Currently Unsupported Features
This feature may be implemented in a future release. Community contributions are welcome!
++++++++++++
== Community
++++++++++++
=== Getting Help
If you have trouble using JJWT, please first read the documentation on this page before asking questions. We try very hard to ensure JJWT's documentation is robust, categorized with a table of contents, and up to date for each release.
++++++++++++
==== Questions
If the documentation or the API JavaDoc isn't sufficient, and you either have usability questions or are confused about something, please https://github.com/jwtk/jjwt/discussions/new?category=q-a[ask your question here]. However:
Please do not create a GitHub issue to ask a question.
We use GitHub Issues to track actionable work that requires changes to JJWT's design and/or codebase. If you have a usability question, instead please https://github.com/jwtk/jjwt/discussions/new?category=q-a[ask your question here], and we can convert that to an issue if necessary.
If a GitHub Issue is created that does not represent actionable work for JJWT's codebase, it will be promptly closed.
++++++++++++
==== Bugs, Feature Requests, Ideas and General Discussions
If you do not have a usability question and believe you have a legitimate bug or feature request, please https://github.com/jwtk/jjwt/discussions[discuss it here] FIRST. Please do a quick search first to see if an existing discussion related to yours exist already and join that existing discussion if necesary.
If you feel like you'd like to help fix a bug or implement the new feature yourself, please read the Contributing section next before starting any work.
++++++++++++
=== Contributing
++++++++++++
==== Pull Requests
Simple Pull Requests that fix anything other than JJWT core code (documentation, JavaDoc, typos, test cases, etc) are always appreciated and have a high likelihood of being merged quickly. Please send them!
However, if you want or feel the need to change JJWT's functionality or core code, please do not issue a pull request without https://github.com/jwtk/jjwt/discussions[starting a new JJWT discussion] and discussing your desired changes first, before you start working on it.
It would be a shame to reject your earnest and genuinely-appreciated pull request if it might not align with the project's goals, design expectations or planned functionality. We've sadly had to reject large PRs in the past because they were out of sync with project or design expectations - all because the PR author didn't first check in with the team first before working on a solution.
So, please https://github.com/jwtk/jjwt/discussions[create a new JJWT discussion] first to discuss, and then we can see easily convert the discussion to an issue and then see if (or how) a PR is warranted. Thank you!
++++++++++++
==== Help Wanted
If you would like to help, but don't know where to start, please visit the https://github.com/jwtk/jjwt/labels/help%20wanted[Help Wanted Issues] page and pick any of the ones there, and we'll be happy to discuss and answer questions in the issue comments.
If any of those don't appeal to you, no worries! Any help you would like to offer would be appreciated based on the above caveats concerning <<contributing-pull-requests,contributing pull requests>>. Feel free to https://github.com/jwtk/jjwt/discussions[discuss or ask questions first] if you're not sure. :)
When you're ready to build and test the project locally, see link:CONTRIBUTING.md[CONTRIBUTING.md].
++++++++++++
== What is a JSON Web Token?
JSON Web Token (JWT) is a general-purpose text-based messaging format for transmitting information in a compact and secure way. Contrary to popular belief, JWT is not just useful for sending and receiving identity tokens on the web - even if that is the most common use case. JWTs can be used as messages for any type of data.
A JWT in its simplest form contains two parts:
. The primary data within the JWT, called the payload, and
. A JSON Object with name/value pairs that represent metadata about the payload and the
message itself, called the header.
A JWT payload can be absolutely anything at all - anything that can be represented as a byte array, such
Adapter for Jackson 3.0
JWE with no "cty" where content accidentally looks like JSON cannot be decrypted with parseEncryptedContent
AndroidKeyStore RSA keys not able to be used for signing
`JacksonSerializer` does not respect `JsonTypeInfo`
RFC 9964: ML-DSA post-quantum signature algorithm
[Javadoc] The javadoc for JwtParser.parse does not specifically guarantee validation of iat and nbf
isSigned returns true if normal JSON provided or singed with different key
Support non-blocking keylocators
Functional interface cleanup
Enable JDK9+ module-info