public interface Header extends Map<String,Object>
This is an immutable JSON map with convenient type-safe getters for JWT standard header parameter names.
Because this interface extends Map<String, Object>
, you can use standard Map
accessor/iterator methods as desired, for example:
header.get("someKey");
However, because Header
instances are immutable, calling any of the map mutation methods
(such as Map.
put
, etc) will result in a runtime exception.
Security
The Header
interface itself makes no implications of integrity protection via either digital signatures or
encryption. Instead, JwsHeader
and JweHeader
represent this information for respective
Jws
and Jwe
instances.
ProtectedHeader
,
JwsHeader
,
JweHeader
Modifier and Type | Field and Description |
---|---|
static String |
ALGORITHM
Deprecated.
since 0.12.0 in favor of
getAlgorithm() . |
static String |
COMPRESSION_ALGORITHM
Deprecated.
since 0.12.0 in favor of
getCompressionAlgorithm() |
static String |
CONTENT_TYPE
Deprecated.
since 0.12.0 in favor of
getContentType() . |
static String |
DEPRECATED_COMPRESSION_ALGORITHM
Deprecated.
use
COMPRESSION_ALGORITHM instead. |
static String |
JWT_TYPE
Deprecated.
since 0.12.0 - this constant is never used within the JJWT codebase.
|
static String |
TYPE
Deprecated.
since 0.12.0 in favor of
getType() . |
Modifier and Type | Method and Description |
---|---|
String |
getAlgorithm()
Returns the JWT
alg (Algorithm) header value or null if not present. |
String |
getCompressionAlgorithm()
Returns the JWT
zip
(Compression Algorithm) header parameter value or null if not present. |
String |
getContentType()
Returns the
cty (Content Type) header value or null if not present. |
String |
getType()
Returns the
typ (Type) header value or null if not present. |
@Deprecated static final String JWT_TYPE
Type
(typ) value: "JWT"
@Deprecated static final String TYPE
getType()
.Type
header parameter name: "typ"
@Deprecated static final String CONTENT_TYPE
getContentType()
.Content Type
header parameter name: "cty"
@Deprecated static final String ALGORITHM
getAlgorithm()
.Algorithm
header parameter name: "alg"
.@Deprecated static final String COMPRESSION_ALGORITHM
getCompressionAlgorithm()
Compression Algorithm
header parameter name: "zip"
@Deprecated static final String DEPRECATED_COMPRESSION_ALGORITHM
COMPRESSION_ALGORITHM
instead."calg"
String getType()
typ
(Type) header value or null
if not present.typ
header value or null
if not present.String getContentType()
cty
(Content Type) header value or null
if not present.
The cty
(Content Type) Header Parameter is used by applications to declare the
IANA MediaType of the content
(the payload). This is intended for use by the application when more than
one kind of object could be present in the Payload; the application can use this value to disambiguate among
the different kinds of objects that might be present. It will typically not be used by applications when
the kind of object is already known. This parameter is ignored by JWT implementations (like JJWT); any
processing of this parameter is performed by the JWS application. Use of this Header Parameter is OPTIONAL.
To keep messages compact in common situations, it is RECOMMENDED that producers omit an
application/
prefix of a media type value in a cty
Header Parameter when
no other '/' appears in the media type value. A recipient using the media type value MUST
treat it as if application/
were prepended to any cty
value not containing a
'/'. For instance, a cty
value of example
SHOULD be used to
represent the application/example
media type, whereas the media type
application/example;part="1/2"
cannot be shortened to
example;part="1/2"
.
typ
header parameter value or null
if not present.String getAlgorithm()
alg
(Algorithm) header value or null
if not present.
alg
(Algorithm) header parameter identifies the cryptographic algorithm used to secure the
JWS. Consider using Jwts.SIG
.get(id)
to convert this string value to a type-safe SecureDigestAlgorithm
instance.alg
(Algorithm) header parameter
identifies the cryptographic key management algorithm used to encrypt or determine the value of the Content
Encryption Key (CEK). The encrypted content is not usable if the alg
value does not represent a
supported algorithm, or if the recipient does not have a key that can be used with that algorithm. Consider
using Jwts.KEY
.get(id)
to convert this string value
to a type-safe KeyAlgorithm
instance.alg
header value or null
if not present. This will always be
non-null
on validly constructed JWT instances, but could be null
during construction.String getCompressionAlgorithm()
zip
(Compression Algorithm) header parameter value or null
if not present.
Compatibility Note
While the JWT family of specifications only defines the zip
header in the JWE
(JSON Web Encryption) specification, JJWT will also support compression for JWS as well if you choose to use it.
However, be aware that if you use compression when creating a JWS token, other libraries may not be able to
parse the JWS. However, compression when creating JWE tokens should be universally accepted for any library
that supports JWE.
zip
header parameter value or null
if not present.Copyright © 2014–2025 jsonwebtoken.io. All rights reserved.