Package com.nimbusds.jose
Class Payload
java.lang.Object
com.nimbusds.jose.Payload
- All Implemented Interfaces:
Serializable
Payload of an unsecured (plain), JSON Web Signature (JWS) or JSON Web
Encryption (JWE) object. Supports JSON object, string, byte array,
Base64URL, JWS object and signed JWT payload representations. This class is
immutable.
UTF-8 is the character set for all conversions between strings and byte arrays.
Conversion relations:
JSON object <=> String <=> Base64URL <=> byte[] <=> JWSObject <=> SignedJWT
- Version:
- 2024-04-20
- Author:
- Vladimir Dzhuvinov
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration of the original data types used to create aPayload
. -
Constructor Summary
ConstructorDescriptionPayload
(byte[] bytes) Creates a new payload from the specified byte array.Creates a new payload from the specified JWS object.Creates a new payload from the specified Base64URL-encoded object.Creates a new payload from the specified signed JSON Web Token (JWT).Creates a new payload from the specified string.Creates a new payload from the specified JSON object. -
Method Summary
Modifier and TypeMethodDescriptionGets the original data type used to create this payload.Returns a Base64URL representation of this payload, as required for JOSE serialisation (see RFC 7515, section 7).byte[]
toBytes()
Returns a byte array representation of this payload.Returns a JSON object representation of this payload.Returns a JWS object representation of this payload.Returns a signed JSON Web Token (JWT) representation of this payload.toString()
Returns a string representation of this payload.<T> T
toType
(PayloadTransformer<T> transformer) Returns a transformation of this payload.
-
Constructor Details
-
Payload
Creates a new payload from the specified JSON object.- Parameters:
jsonObject
- The JSON object representing the payload. Must not benull
.
-
Payload
Creates a new payload from the specified string.- Parameters:
string
- The string representing the payload. Must not benull
.
-
Payload
Creates a new payload from the specified byte array.- Parameters:
bytes
- The byte array representing the payload. Must not benull
.
-
Payload
Creates a new payload from the specified Base64URL-encoded object.- Parameters:
base64URL
- The Base64URL-encoded object representing the payload. Must not benull
.
-
Payload
Creates a new payload from the specified JWS object. Intended for signed then encrypted JOSE objects.- Parameters:
jwsObject
- The JWS object representing the payload. Must be in a signed state and notnull
.
-
Payload
Creates a new payload from the specified signed JSON Web Token (JWT). Intended for signed then encrypted JWTs.- Parameters:
signedJWT
- The signed JWT representing the payload. Must be in a signed state and notnull
.
-
-
Method Details
-
getOrigin
Gets the original data type used to create this payload.- Returns:
- The payload origin.
-
toJSONObject
Returns a JSON object representation of this payload.- Returns:
- The JSON object representation,
null
if the payload couldn't be converted to a JSON object.
-
toString
Returns a string representation of this payload. -
toBytes
Returns a byte array representation of this payload.- Returns:
- The byte array representation.
-
toBase64URL
Returns a Base64URL representation of this payload, as required for JOSE serialisation (see RFC 7515, section 7).- Returns:
- The Base64URL representation.
-
toJWSObject
Returns a JWS object representation of this payload. Intended for signed then encrypted JOSE objects.- Returns:
- The JWS object representation,
null
if the payload couldn't be converted to a JWS object.
-
toSignedJWT
Returns a signed JSON Web Token (JWT) representation of this payload. Intended for signed then encrypted JWTs.- Returns:
- The signed JWT representation,
null
if the payload couldn't be converted to a signed JWT.
-
toType
Returns a transformation of this payload.- Type Parameters:
T
- Type of the result.- Parameters:
transformer
- The payload transformer. Must not benull
.- Returns:
- The transformed payload.
-