Class JOSEHeader
java.lang.Object
de.christofreichardt.json.websignature.JOSEHeader
- All Implemented Interfaces:
de.christofreichardt.diagnosis.Traceable
A convenient class useful to define a JOSE Header containing the parameters describing the cryptographic operations and parameters employed. At present only a subset
of the header parameter specified within RFC 7515 is supported. To create an actual
JOSEHeader instance use one of the static factory methods. Two of them provide
special builders to programmatically create a JOSEHeader instance. The third expects a suitable JsonObject.
Example
First we generate a key pair and build a JSON Web Key:KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC");
ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp256r1");
keyPairGenerator.initialize(ecGenParameterSpec);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
JsonWebPublicKey jsonWebPublicKey = JsonWebPublicKey.of(keyPair.getPublic())
.withKid(UUID.randomUUID().toString())
.build();
Now we can programmatically build a JOSEHeader:
JOSEHeader joseHeader = JOSEHeader.of(jsonWebPublicKey)
.withTyp("JWT")
.build();- Author:
- Christof Reichardt
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder for aJOSEHeaderpreconfigured with the "alg" parameter.static final classA builder for aJOSEHeaderpreconfigured with a JSON web (public) key. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this JOSE header is equal to another header.static JOSEHeaderfromJson(jakarta.json.JsonObject joseHeaderView) Factory method to create aJOSEHeaderinstance from a plainJsonObject.getAlg()Returns the configured "alg" (Algorithm).de.christofreichardt.diagnosis.AbstractTracerReturns the configured "jwk" (JSON Web Key)getKid()Returns the configured "kid" (Key ID)getTyp()Returns the configured "typ" (Type).inthashCode()A hash code for this header.static JOSEHeader.PublicKeyBuilderof(JsonWebPublicKey jsonWebPublicKey) Creates a special builder for aJOSEHeader.static JOSEHeader.AlgorithmBuilderCreates a special builder for aJOSEHeader.jakarta.json.JsonObjecttoJson()Converts thisJOSEHeaderinto a plainJsonObject.
-
Method Details
-
getAlg
Returns the configured "alg" (Algorithm).- Returns:
- the configured "alg".
- See Also:
-
getTyp
Returns the configured "typ" (Type).- Returns:
- the configured "typ".
- See Also:
-
getKid
Returns the configured "kid" (Key ID)- Returns:
- the configured "kid".
- See Also:
-
getJsonWebPublicKey
Returns the configured "jwk" (JSON Web Key)- Returns:
- the configured "jwk".
- See Also:
-
equals
Checks if this JOSE header is equal to another header. Compares thisJOSEHeaderwith another ensuring that it contains the same configuration. Only objects of typeJOSEHeaderare considered, other types return false. -
hashCode
-
of
Creates a special builder for aJOSEHeader. Use this variant to build aJOSEHeaderif you don't want to specify a JSON web key within the header.- Parameters:
alg- the desired "alg" parameter.- Returns:
- an
AlgorithmBuilder.
-
of
Creates a special builder for aJOSEHeader. Use this variant to build aJOSEHeaderif you want to specify a JSON web key within the header. The corresponding "alg" parameter will be deduced from the given public key.- Parameters:
jsonWebPublicKey- the desired public key referenced by the "jwk" parameter.- Returns:
- a
PublicKeyBuilder.
-
toJson
public jakarta.json.JsonObject toJson()Converts thisJOSEHeaderinto a plainJsonObject.- Returns:
- a
JsonObjectcorresponding to thisJOSEHeader - See Also:
-
fromJson
public static JOSEHeader fromJson(jakarta.json.JsonObject joseHeaderView) throws GeneralSecurityException Factory method to create aJOSEHeaderinstance from a plainJsonObject.- Parameters:
joseHeaderView- the givenJsonObject.- Returns:
- a
JOSEHeader - Throws:
GeneralSecurityException- forwarded from the Java Platform API, indicates difficulties when creating a JSON web key from the givenJsonObject.- See Also:
-
getCurrentTracer
public de.christofreichardt.diagnosis.AbstractTracer getCurrentTracer()- Specified by:
getCurrentTracerin interfacede.christofreichardt.diagnosis.Traceable
-