K - the type of Java Key represented by the constructed JWK.J - the type of Jwk created by the builderT - the type of the builder, for subtype method chainingpublic interface JwkBuilder<K extends Key,J extends Jwk<K>,T extends JwkBuilder<K,J,T>> extends MapMutator<String,Object,T>, SecurityBuilder<J,T>, KeyOperationPolicied<T>
SecurityBuilder that produces a JWK. A JWK is an immutable set of name/value pairs that represent a
cryptographic key as defined by
RFC 7517: JSON Web Key (JWK).
The JwkBuilder interface represents common JWK properties that may be specified for any type of JWK.
Builder subtypes support additional JWK properties specific to different types of cryptographic keys
(e.g. Secret, Asymmetric, RSA, Elliptic Curve, etc).SecretJwkBuilder,
RsaPublicJwkBuilder,
RsaPrivateJwkBuilder,
EcPublicJwkBuilder,
EcPrivateJwkBuilder,
OctetPublicJwkBuilder,
OctetPrivateJwkBuilder| Modifier and Type | Method and Description |
|---|---|
T |
algorithm(String alg)
Sets the JWK
alg (Algorithm)
Parameter. |
T |
id(String kid)
Sets the JWK
kid (Key ID)
Parameter. |
T |
idFromThumbprint()
|
T |
idFromThumbprint(HashAlgorithm alg)
Sets the JWK's
kid value to be the Base64URL-encoding of its
thumbprint using the specified HashAlgorithm. |
NestedCollection<KeyOperation,T> |
operations()
Configures the key operations for which
the key is intended to be used.
|
add, add, delete, emptyprovider, randomoperationPolicyT algorithm(String alg) throws IllegalArgumentException
alg (Algorithm)
Parameter.
The alg (algorithm) parameter identifies the algorithm intended for use with the key. The
value specified should either be one of the values in the IANA
JSON Web Signature and Encryption
Algorithms registry or be a value that contains a Collision-Resistant Name. The alg
must be a CaSe-SeNsItIvE ASCII string.
alg - the JWK alg value.IllegalArgumentException - if alg is null or empty.T id(String kid) throws IllegalArgumentException
kid (Key ID)
Parameter.
The kid (key ID) parameter is used to match a specific key. This is used, for instance,
to choose among a set of keys within a JWK Set during key rollover. The structure of the
kid value is unspecified. When kid values are used within a JWK Set, different keys
within the JWK Set SHOULD use distinct kid values. (One example in which
different keys might use the same kid value is if they have different kty (key type)
values but are considered to be equivalent alternatives by the application using them.)
The kid value is a CaSe-SeNsItIvE string, and it is optional. When used with JWS or JWE,
the kid value is used to match a JWS or JWE kid Header Parameter value.
kid - the JWK kid value.IllegalArgumentException - if the argument is null or empty.T idFromThumbprint()
kid value to be the Base64URL-encoding of its SHA-256
thumbprint. That is, the constructed JWK's kid value will equal
jwk.thumbprint(Jwks.HASH.SHA256).toString().
This is a convenience method that delegates to idFromThumbprint(HashAlgorithm) using
Jwks.HASH.SHA256.
T idFromThumbprint(HashAlgorithm alg)
kid value to be the Base64URL-encoding of its
thumbprint using the specified HashAlgorithm. That is, the
constructed JWK's kid value will equal
thumbprint(alg).toString().alg - the hash algorithm to use to compute the thumbprint.Jwks.HASHNestedCollection<KeyOperation,T> operations()
and() method to
return to the JWK builder, for example:
jwkBuilder.operations().add(aKeyOperation).and()// etc...
The and() method will throw an IllegalArgumentException if any of the specified
KeyOperations are not permitted by the JWK's
operationPolicy. See that documentation for more
information on security vulnerabilities when using the same key with multiple algorithms.
Standard KeyOperations and Overrides
All RFC-standard JWK Key Operations in the Jwks.OP registry are supported via the builder's default
operationPolicy, but other (custom) values
MAY be specified (for example, using a Jwks.OP.builder()).
If the JwkBuilder is being used to rebuild or parse an existing JWK however, any custom operations
should be enabled by configuring an operationPolicy
that includes the custom values (e.g. via
Jwks.OP.policy().add(customKeyOperation)).
For best interoperability with other applications however, it is recommended to use only the Jwks.OP
constants.
NestedCollection to use for key_ops configuration.Jwks.OP,
RFC 7517: key_ops (Key Operations) ParameterCopyright © 2014–2024 jsonwebtoken.io. All rights reserved.