Package com.nimbusds.jose
Class JWEObject
java.lang.Object
com.nimbusds.jose.JOSEObject
com.nimbusds.jose.JWEObject
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
EncryptedJWT
JSON Web Encryption (JWE) secured object with
compact
serialisation.
This class is thread-safe.
- Version:
- 2023-03-26
- Author:
- Vladimir Dzhuvinov, Egor Puzanov
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of the states of a JSON Web Encryption (JWE) 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-encrypted JSON Web Encryption (JWE) object with the specified header and payload.JWEObject(Base64URL firstPart, Base64URL secondPart, Base64URL thirdPart, Base64URL fourthPart, Base64URL fifthPart) Creates a new encrypted JSON Web Encryption (JWE) object with the specified serialised parts. -
Method Summary
Modifier and TypeMethodDescriptionvoiddecrypt(JWEDecrypter decrypter) Decrypts this JWE object with the specified decrypter.voidencrypt(JWEEncrypter encrypter) Encrypts this JWE object with the specified encrypter.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 header of this JOSE object.getIV()Returns the initialisation vector (IV) of this JWE object.getState()Returns the state of the JWE secured object.static JWEObjectParses a JWE object from the specified string in compact form.Serialises this JWE object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters.Methods inherited from class com.nimbusds.jose.JOSEObject
getParsedParts, getParsedString, getPayload, setParsedParts, setPayload, split
-
Constructor Details
-
JWEObject
Creates a new to-be-encrypted JSON Web Encryption (JWE) object with the specified header and payload. The initial state will beunencrypted.- Parameters:
header- The JWE header. Must not benull.payload- The payload. Must not benull.
-
JWEObject
public JWEObject(Base64URL firstPart, Base64URL secondPart, Base64URL thirdPart, Base64URL fourthPart, Base64URL fifthPart) throws ParseException Creates a new encrypted JSON Web Encryption (JWE) object with the specified serialised parts. The state will beencrypted.- Parameters:
firstPart- The first part, corresponding to the JWE header. Must not benull.secondPart- The second part, corresponding to the encrypted key. Empty ornullif none.thirdPart- The third part, corresponding to the initialisation vector. Empty ornullif none.fourthPart- The fourth part, corresponding to the cipher text. Must not benull.fifthPart- The fifth part, corresponding to the authentication tag. Empty ofnullif none.- 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.
-
getEncryptedKey
Returns the encrypted key of this JWE object.- Returns:
- The encrypted key,
nullnot 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),
nullif not applicable or the JWE object has not been encrypted yet.
-
getCipherText
Returns the cipher text of this JWE object.- Returns:
- The cipher text,
nullif the JWE object has not been encrypted yet.
-
getAuthTag
Returns the authentication tag of this JWE object.- Returns:
- The authentication tag,
nullif not applicable or the JWE object has not been encrypted yet.
-
getState
Returns the state of the JWE secured object.- Returns:
- The state.
-
encrypt
Encrypts this JWE object with the specified encrypter. The JWE object must be in anunencryptedstate.- 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 aencryptedstate.- 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.
-
serialize
Serialises this JWE object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters. It must be in aencryptedordecryptedstate.[header-base64url].[encryptedKey-base64url].[iv-base64url].[cipherText-base64url].[authTag-base64url]
- Specified by:
serializein classJOSEObject- Returns:
- The serialised JWE object.
- Throws:
IllegalStateException- If the JWE object is not in aencryptedordecrypted state.
-
parse
Parses a JWE object from the specified string in compact form. The parsed JWE object will be given anJWEObject.State.ENCRYPTEDstate.- Parameters:
s- The string to parse. Must not benull.- Returns:
- The JWE object.
- Throws:
ParseException- If the string couldn't be parsed to a valid JWE object.
-