Package com.nimbusds.jose
Class JWSObject
java.lang.Object
com.nimbusds.jose.JOSEObject
com.nimbusds.jose.JWSObject
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SignedJWT
JSON Web Signature (JWS) secured object with
compact
serialisation.
This class is thread-safe.
- Version:
- 2022-09-27
- Author:
- Vladimir Dzhuvinov
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of the states of a JSON Web Signature (JWS) secured object. -
Field Summary
Fields inherited from class com.nimbusds.jose.JOSEObject
MIME_TYPE_COMPACT, MIME_TYPE_JS -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new to-be-signed JSON Web Signature (JWS) object with the specified header and payload.Creates a new signed JSON Web Signature (JWS) object with the specified serialised parts and payload which can be optionally unencoded (RFC 7797).Creates a new signed JSON Web Signature (JWS) object with the specified serialised parts. -
Method Summary
Modifier and TypeMethodDescriptionReturns the header of this JOSE object.Returns the signature of this JWS object.byte[]Returns the signing input for this JWS object.getState()Returns the state of the JWS secured object.static JWSObjectParses a JWS object from the specified string in compact format.static JWSObjectParses a JWS object from the specified string in compact format and a detached payload which can be optionally unencoded (RFC 7797).Serialises this JWS object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters.serialize(boolean detachedPayload) Serialises this JWS object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters.voidSigns this JWS object with the specified signer.booleanverify(JWSVerifier verifier) Checks the signature of this JWS object with the specified verifier.Methods inherited from class com.nimbusds.jose.JOSEObject
getParsedParts, getParsedString, getPayload, setParsedParts, setPayload, split
-
Constructor Details
-
JWSObject
Creates a new to-be-signed JSON Web Signature (JWS) object with the specified header and payload. The initial state will beunsigned.- Parameters:
header- The JWS header. Must not benull.payload- The payload. Must not benull.
-
JWSObject
public JWSObject(Base64URL firstPart, Base64URL secondPart, Base64URL thirdPart) throws ParseException Creates a new signed JSON Web Signature (JWS) object with the specified serialised parts. The state will besigned.- Parameters:
firstPart- The first part, corresponding to the JWS header. Must not benull.secondPart- The second part, corresponding to the payload. Must not benull.thirdPart- The third part, corresponding to the signature. Must not benull.- Throws:
ParseException- If parsing of the serialised parts failed.
-
JWSObject
Creates a new signed JSON Web Signature (JWS) object with the specified serialised parts and payload which can be optionally unencoded (RFC 7797). The state will besigned.- Parameters:
firstPart- The first part, corresponding to the JWS header. Must not benull.payload- The payload. Must not benull.thirdPart- The third part, corresponding to the signature. Must not benull.- Throws:
ParseException- If parsing of the serialised parts failed.
-
-
Method Details
-
getHeader
Description copied from class:JOSEObjectReturns the header of this JOSE object.- Specified by:
getHeaderin classJOSEObject- Returns:
- The header.
-
getSigningInput
Returns the signing input for this JWS object.- Returns:
- The signing input, to be passed to a JWS signer or verifier.
-
getSignature
Returns the signature of this JWS object.- Returns:
- The signature,
nullif the JWS object is not signed yet.
-
getState
Returns the state of the JWS secured object.- Returns:
- The state.
-
sign
Signs this JWS object with the specified signer. The JWS object must be in aunsignedstate.- Parameters:
signer- The JWS signer. Must not benull.- Throws:
IllegalStateException- If the JWS object is not in anunsigned state.JOSEException- If the JWS object couldn't be signed.
-
verify
Checks the signature of this JWS object with the specified verifier. The JWS object must be in asignedstate.- Parameters:
verifier- The JWS verifier. Must not benull.- Returns:
trueif the signature was successfully verified, elsefalse.- Throws:
IllegalStateException- If the JWS object is not in asignedorverified state.JOSEException- If the JWS object couldn't be verified.
-
serialize
Serialises this JWS object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters. It must be in asignedorverifiedstate.[header-base64url].[payload-base64url].[signature-base64url]
- Specified by:
serializein classJOSEObject- Returns:
- The serialised JWS object.
- Throws:
IllegalStateException- If the JWS object is not in asignedorverifiedstate.
-
serialize
Serialises this JWS object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters. It must be in asignedorverifiedstate.- Parameters:
detachedPayload-trueto return a serialised object with a detached payload compliant with RFC 7797,falsefor regular JWS serialisation.- Returns:
- The serialised JOSE object.
- Throws:
IllegalStateException- If the JOSE object is not in a state that permits serialisation.
-
parse
Parses a JWS object from the specified string in compact format. The parsed JWS object will be given aJWSObject.State.SIGNEDstate.- Parameters:
s- The JWS string to parse. Must not benull.- Returns:
- The JWS object.
- Throws:
ParseException- If the string couldn't be parsed to a JWS object.
-
parse
Parses a JWS object from the specified string in compact format and a detached payload which can be optionally unencoded (RFC 7797). The parsed JWS object will be given aJWSObject.State.SIGNEDstate.- Parameters:
s- The JWS string to parse for a detached payload. Must not benull.detachedPayload- The detached payload, optionally unencoded (RFC 7797). Must not benull.- Returns:
- The JWS object.
- Throws:
ParseException- If the string couldn't be parsed to a JWS object.
-