@ThreadSafe public class JWSObject extends JOSEObject
Modifier and Type | Class and Description |
---|---|
static class |
JWSObject.State
Enumeration of the states of a JSON Web Signature (JWS) object.
|
MIME_TYPE_COMPACT, MIME_TYPE_JS
Constructor and Description |
---|
JWSObject(Base64URL firstPart,
Base64URL secondPart,
Base64URL thirdPart)
Creates a new signed JSON Web Signature (JWS) object with the
specified serialised parts.
|
JWSObject(Base64URL firstPart,
Payload payload,
Base64URL thirdPart)
Creates a new signed JSON Web Signature (JWS) object with the
specified serialised parts and payload which can be optionally
unencoded (RFC 7797).
|
JWSObject(JWSHeader header,
Payload payload)
Creates a new to-be-signed JSON Web Signature (JWS) object with the
specified header and payload.
|
Modifier and Type | Method and Description |
---|---|
JWSHeader |
getHeader()
Returns the header of this JOSE object.
|
Base64URL |
getSignature()
Returns the signature of this JWS object.
|
byte[] |
getSigningInput()
Returns the signing input for this JWS object.
|
JWSObject.State |
getState()
Returns the state of this JWS object.
|
static JWSObject |
parse(String s)
Parses a JWS object from the specified string in compact format.
|
static JWSObject |
parse(String s,
Payload detachedPayload)
Parses a JWS object from the specified string in compact format and
a detached payload which can be optionally unencoded (RFC 7797).
|
String |
serialize()
Serialises this JWS object to its compact format consisting of
Base64URL-encoded parts delimited by period ('.') characters.
|
String |
serialize(boolean detachedPayload)
Serialises this JWS object to its compact format consisting of
Base64URL-encoded parts delimited by period ('.') characters.
|
void |
sign(JWSSigner signer)
Signs this JWS object with the specified signer.
|
boolean |
verify(JWSVerifier verifier)
Checks the signature of this JWS object with the specified verifier.
|
getParsedParts, getParsedString, getPayload, setParsedParts, setPayload, split
public JWSObject(JWSHeader header, Payload payload)
unsigned
.header
- The JWS header. Must not be null
.payload
- The payload. Must not be null
.public JWSObject(Base64URL firstPart, Base64URL secondPart, Base64URL thirdPart) throws ParseException
signed
.firstPart
- The first part, corresponding to the JWS header.
Must not be null
.secondPart
- The second part, corresponding to the payload.
Must not be null
.thirdPart
- The third part, corresponding to the signature.
Must not be null
.ParseException
- If parsing of the serialised parts failed.public JWSObject(Base64URL firstPart, Payload payload, Base64URL thirdPart) throws ParseException
signed
.firstPart
- The first part, corresponding to the JWS header.
Must not be null
.payload
- The payload. Must not be null
.thirdPart
- The third part, corresponding to the signature.
Must not be null
.ParseException
- If parsing of the serialised parts failed.public JWSHeader getHeader()
JOSEObject
getHeader
in class JOSEObject
public byte[] getSigningInput()
public Base64URL getSignature()
null
if the JWS object is not signed
yet.public JWSObject.State getState()
public void sign(JWSSigner signer) throws JOSEException
unsigned
state.signer
- The JWS signer. Must not be null
.IllegalStateException
- If the JWS object is not in an
unsigned state
.JOSEException
- If the JWS object couldn't be signed.public boolean verify(JWSVerifier verifier) throws JOSEException
signed
state.verifier
- The JWS verifier. Must not be null
.true
if the signature was successfully verified,
else false
.IllegalStateException
- If the JWS object is not in a
signed
or
verified state
.JOSEException
- If the JWS object couldn't be
verified.public String serialize()
signed
or
verified
state.
[header-base64url].[payload-base64url].[signature-base64url]
serialize
in class JOSEObject
IllegalStateException
- If the JWS object is not in a
signed
or
verified
state.public String serialize(boolean detachedPayload)
signed
or
verified
state.detachedPayload
- true
to return a serialised object
with a detached payload compliant with RFC
7797, false
for regular JWS
serialisation.IllegalStateException
- If the JOSE object is not in a state
that permits serialisation.public static JWSObject parse(String s) throws ParseException
JWSObject.State.SIGNED
state.s
- The JWS string to parse. Must not be null
.ParseException
- If the string couldn't be parsed to a JWS
object.public static JWSObject parse(String s, Payload detachedPayload) throws ParseException
JWSObject.State.SIGNED
state.s
- The JWS string to parse for a detached
payload. Must not be null
.detachedPayload
- The detached payload, optionally unencoded
(RFC 7797). Must not be null
.ParseException
- If the string couldn't be parsed to a JWS
object.Copyright © 2021 Connect2id Ltd.. All rights reserved.