Package com.nimbusds.jose
Class JWEObjectJSON
java.lang.Object
com.nimbusds.jose.JOSEObjectJSON
com.nimbusds.jose.JWEObjectJSON
- All Implemented Interfaces:
Serializable
JSON Web Encryption (JWE) secured object with
JSON
serialisation.
This class is thread-safe.
- Version:
- 2024-04-20
- Author:
- Egor Puzanov, Vladimir Dzhuvinov
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Individual recipient in a JWE object serialisable to JSON. -
Field Summary
Fields inherited from class com.nimbusds.jose.JOSEObjectJSON
MIME_TYPE_JOSE_JSON
-
Constructor Summary
ConstructorsConstructorDescriptionJWEObjectJSON
(JWEHeader header, Payload payload) Creates a new to-be-encrypted JSON Web Encryption (JWE) object with the specified JWE protected header and payload.JWEObjectJSON
(JWEHeader header, Payload payload, UnprotectedHeader unprotectedHeader, byte[] aad) Creates a new to-be-encrypted JSON Web Encryption (JWE) object with the specified JWE protected header, payload and Additional Authenticated Data (AAD).JWEObjectJSON
(JWEHeader header, Base64URL cipherText, Base64URL iv, Base64URL authTag, List<JWEObjectJSON.Recipient> recipients, UnprotectedHeader unprotectedHeader, byte[] aad) Creates a new encrypted JSON Web Encryption (JWE) object.JWEObjectJSON
(JWEObject jweObject) Creates a new JWE JSON object from the specified JWE object with compact serialisation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
decrypt
(JWEDecrypter decrypter) Decrypts this JWE object with the specified decrypter.void
encrypt
(JWEEncrypter encrypter) Encrypts this JWE object with the specified encrypter.byte[]
getAAD()
Returns the Additional Authenticated Data (AAD) of this JWE object.Returns the authentication tag of this JWE object.Returns the cipher text of this JWE object.Returns the encrypted key of this JWE object.Returns the JWE protected header of this JWE object.getIV()
Returns the initialisation vector (IV) of this JWE object.Returns the recipients list of the JWE object.getState()
Returns the state of this JWE object.Returns the shared unprotected header of this JWE object.static JWEObjectJSON
Parses a JWE object from the specified JSON object string.static JWEObjectJSON
Parses a JWE object from the specified JSON object representation.Serialises this JOSE object to a flattened JSON object string.Serialises this JOSE object to a general JOSE object string.Returns a flattened JSON object representation of this JOSE secured object.Returns a general JSON object representation of this JOSE secured object.Methods inherited from class com.nimbusds.jose.JOSEObjectJSON
getPayload, setPayload
-
Constructor Details
-
JWEObjectJSON
Creates a new JWE JSON object from the specified JWE object with compact serialisation. The initial state is copied from the JWE object.- Parameters:
jweObject
- The JWE object. Must not benull
.
-
JWEObjectJSON
Creates a new to-be-encrypted JSON Web Encryption (JWE) object with the specified JWE protected header and payload. The initial state will beunencrypted
.- Parameters:
header
- The JWE protected header. Must not benull
.payload
- The payload. Must not benull
.
-
JWEObjectJSON
public JWEObjectJSON(JWEHeader header, Payload payload, UnprotectedHeader unprotectedHeader, byte[] aad) Creates a new to-be-encrypted JSON Web Encryption (JWE) object with the specified JWE protected header, payload and Additional Authenticated Data (AAD). The initial state will beunencrypted
.- Parameters:
header
- The JWE protected header. Must not benull
.payload
- The payload. Must not benull
.unprotectedHeader
- The shared unprotected header, empty ornull
if none.aad
- The additional authenticated data (AAD),null
if none.
-
JWEObjectJSON
public JWEObjectJSON(JWEHeader header, Base64URL cipherText, Base64URL iv, Base64URL authTag, List<JWEObjectJSON.Recipient> recipients, UnprotectedHeader unprotectedHeader, byte[] aad) Creates a new encrypted JSON Web Encryption (JWE) object. The state will beencrypted
.- Parameters:
header
- The JWE protected header. Must not benull
.cipherText
- The cipher text. Must not benull
.iv
- The initialisation vector, empty ornull
if none.authTag
- The authentication tag, empty ornull
if none.recipients
- The recipients list. Must not benull
.unprotectedHeader
- The shared unprotected header, empty ornull
if none.aad
- The additional authenticated data. Must not benull
.
-
-
Method Details
-
getHeader
Returns the JWE protected header of this JWE object.- Returns:
- The JWE protected header.
-
getUnprotectedHeader
Returns the shared unprotected header of this JWE object.- Returns:
- The shared unprotected header, empty or
null
if none.
-
getEncryptedKey
Returns the encrypted key of this JWE object.- Returns:
- The encrypted key,
null
not applicable or the JWE object has not been encrypted yet.
-
getIV
Returns the initialisation vector (IV) of this JWE object.- Returns:
- The initialisation vector (IV),
null
if not applicable or the JWE object has not been encrypted yet.
-
getCipherText
Returns the cipher text of this JWE object.- Returns:
- The cipher text,
null
if the JWE object has not been encrypted yet.
-
getAuthTag
Returns the authentication tag of this JWE object.- Returns:
- The authentication tag,
null
if not applicable or the JWE object has not been encrypted yet.
-
getAAD
Returns the Additional Authenticated Data (AAD) of this JWE object.- Returns:
- The Additional Authenticated Data (AAD).
-
getRecipients
Returns the recipients list of the JWE object.- Returns:
- The recipients list.
-
getState
Returns the state of this JWE object.- Returns:
- The state.
-
encrypt
Encrypts this JWE object with the specified encrypter. The JWE object must be in anunencrypted
state.- Parameters:
encrypter
- The JWE encrypter. Must not benull
.- Throws:
IllegalStateException
- If the JWE object is not in anunencrypted state
.JOSEException
- If the JWE object couldn't be encrypted.
-
decrypt
Decrypts this JWE object with the specified decrypter. The JWE object must be in aencrypted
state.- Parameters:
decrypter
- The JWE decrypter. Must not benull
.- Throws:
IllegalStateException
- If the JWE object is not in anencrypted state
.JOSEException
- If the JWE object couldn't be decrypted.
-
toGeneralJSONObject
Description copied from class:JOSEObjectJSON
Returns a general JSON object representation of this JOSE secured object.- Specified by:
toGeneralJSONObject
in classJOSEObjectJSON
- Returns:
- The JSON object.
-
toFlattenedJSONObject
Description copied from class:JOSEObjectJSON
Returns a flattened JSON object representation of this JOSE secured object. There must be exactly one JWS signature or JWE recipient for a flattened JSON serialisation.See JWS flattened serialisation or JWE flattened serialisation.
- Specified by:
toFlattenedJSONObject
in classJOSEObjectJSON
- Returns:
- The JSON object.
-
serializeGeneral
Description copied from class:JOSEObjectJSON
Serialises this JOSE object to a general JOSE object string.- Specified by:
serializeGeneral
in classJOSEObjectJSON
- Returns:
- The JSON object string.
-
serializeFlattened
Description copied from class:JOSEObjectJSON
Serialises this JOSE object to a flattened JSON object string. There must be exactly one JWS signature or JWE recipient for a flattened JSON serialisation.See JWS flattened serialisation or JWE flattened serialisation.
- Specified by:
serializeFlattened
in classJOSEObjectJSON
- Returns:
- The JSON object string.
-
parse
Parses a JWE object from the specified JSON object representation.- Parameters:
jsonObject
- The JSON object to parse. Must not benull
.- Returns:
- The JWE secured object.
- Throws:
ParseException
- If the JSON object couldn't be parsed to a JWE secured object.
-
parse
Parses a JWE object from the specified JSON object string.- Parameters:
json
- The JSON object string to parse. Must not benull
.- Returns:
- The JWE object.
- Throws:
ParseException
- If the string couldn't be parsed to a JWE object.
-