Package org.forgerock.json.jose.jwe
Class SignedThenEncryptedJwt
java.lang.Object
org.forgerock.json.jose.jwe.EncryptedJwt
org.forgerock.json.jose.jwe.SignedThenEncryptedJwt
A nested signed-then-encrypted JWT.
-
Constructor Summary
ConstructorDescriptionSignedThenEncryptedJwt
(EncryptedJwt encryptedJwt) Constructs a fresh signed-then-encrypted JWT from an encrypted JWT.SignedThenEncryptedJwt
(JweHeader header, String encodedHeader, byte[] encryptedContentEncryptionKey, byte[] initialisationVector, byte[] ciphertext, byte[] authenticationTag) Reconstructs a signed-then-encrypted JWT from components parts of the encrypted JWT string.SignedThenEncryptedJwt
(JweHeader header, SignedJwt payload, Key publicKey) Constructs a fresh signed-then-encrypted JWT with the given signed JWT payload, JWE headers and encryption key. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Create a copy of the current JWT.decrypt
(SecretsProvider secretsProvider, Purpose<? extends CryptoKey> purpose) Attempts to decrypt the JWT using any available keys for the givenPurpose
from the givenSecretsProvider
.decrypt
(ValidSecretsReference<? extends CryptoKey, NeverThrowsException> validSecretsReference) Attempts to decrypt the JWT using any available keys from the givenValidSecretsReference
.boolean
decryptAndVerify
(Key decryptionKey, SigningHandler signingHandler) Deprecated.decryptAndVerify
(SecretsProvider secretsProvider, Purpose<? extends CryptoKey> decryptionPurpose, Purpose<VerificationKey> verificationPurpose) Decrypts the outer JWT and then verifies the signature on the inner JWT using secrets from the suppliedSecretsProvider
.decryptAndVerify
(ValidSecretsReference<? extends CryptoKey, NeverThrowsException> decryptionSecretsReference, ValidSecretsReference<VerificationKey, NeverThrowsException> verificationSecretsReference) Decrypts the outer JWT and then verifies the signature on the inner JWT using supplied valid secrets.Gets the claims set object for the Jwt, which contains all of the claims (name value pairs) conveyed by the JWT.Get the signed JWT.boolean
verify
(SigningHandler signingHandler) Verifies that the signature is valid on the nested signed JWT.Methods inherited from class org.forgerock.json.jose.jwe.EncryptedJwt
build, decrypt, decryptRawPayload, decryptRawPayload, decryptRawPayload, getHeader
-
Constructor Details
-
SignedThenEncryptedJwt
Constructs a fresh signed-then-encrypted JWT from an encrypted JWT. To use if you know that the encrypted JWT is actually containing a JWS.- Parameters:
encryptedJwt
- the encrypted JWT.
-
SignedThenEncryptedJwt
Constructs a fresh signed-then-encrypted JWT with the given signed JWT payload, JWE headers and encryption key.- Parameters:
header
- the JWE headers.payload
- the signed JWT payload.publicKey
- the encryption key.
-
SignedThenEncryptedJwt
public SignedThenEncryptedJwt(JweHeader header, String encodedHeader, byte[] encryptedContentEncryptionKey, byte[] initialisationVector, byte[] ciphertext, byte[] authenticationTag) Reconstructs a signed-then-encrypted JWT from components parts of the encrypted JWT string.- Parameters:
header
- the decoded headers.encodedHeader
- the encoded headers.encryptedContentEncryptionKey
- the encrypted content encryption key (CEK), or null if not used.initialisationVector
- the initialisation vector (IV).ciphertext
- the encrypted ciphertext payload.authenticationTag
- the authentication MAC tag.
-
-
Method Details
-
verify
Verifies that the signature is valid on the nested signed JWT.- Parameters:
signingHandler
- the handler to use for verifying the signature.- Returns:
- true if the signature is valid, otherwise false.
- Throws:
JwsVerifyingException
- if the outer JWT has not already been decrypted.
-
decryptAndVerify
Deprecated.PreferdecryptAndVerify(SecretsProvider, Purpose, Purpose)
instead.Decrypts the outer JWT and then verifies the signature on the inner JWT.- Parameters:
decryptionKey
- the decryption key for the outer JWE.signingHandler
- the signing handler for verifying the nested JWS.- Returns:
- true if the nested signature is valid, otherwise false.
- Throws:
JweDecryptionException
- if the JWE cannot be decrypted.
-
decrypt
public Promise<SignedThenEncryptedJwt,JweDecryptionCheckedException> decrypt(SecretsProvider secretsProvider, Purpose<? extends CryptoKey> purpose) Description copied from class:EncryptedJwt
Attempts to decrypt the JWT using any available keys for the givenPurpose
from the givenSecretsProvider
. Only keys that support the JWT algorithm will be considered. If decryption is successful then this returns aPromise
for the same JWT with the payload decrypted, otherwise it returns a promise that resolves to aJweDecryptionCheckedException
.- Overrides:
decrypt
in classEncryptedJwt
- Parameters:
secretsProvider
- the secrets provider from which to retrieve keys.purpose
- the purpose for which decryption is being performed. Typically this purpose will be for aDataDecryptionKey
,KeyDecryptionKey
, orKeyAgreementKey
.- Returns:
- a promise to either the decrypted JWT or a failed promise indicating that decryption failed.
-
decrypt
public Promise<SignedThenEncryptedJwt,JweDecryptionCheckedException> decrypt(ValidSecretsReference<? extends CryptoKey, NeverThrowsException> validSecretsReference) Description copied from class:EncryptedJwt
Attempts to decrypt the JWT using any available keys from the givenValidSecretsReference
. Only keys that support the JWT algorithm will be considered. If decryption is successful then this returns aPromise
for the same JWT with the payload decrypted, otherwise it returns a promise that resolves to aJweDecryptionCheckedException
.- Overrides:
decrypt
in classEncryptedJwt
- Parameters:
validSecretsReference
- the reference to valid secrets.- Returns:
- a promise to either the decrypted JWT or a failed promise indicating that decryption failed.
-
decryptAndVerify
public Promise<SignedThenEncryptedJwt,JweDecryptionCheckedException> decryptAndVerify(SecretsProvider secretsProvider, Purpose<? extends CryptoKey> decryptionPurpose, Purpose<VerificationKey> verificationPurpose) Decrypts the outer JWT and then verifies the signature on the inner JWT using secrets from the suppliedSecretsProvider
. If decryption and verification are successful then it returns the decrypted and verified JWT as a promise, otherwise the promise will resolve to aJweDecryptionCheckedException
.- Parameters:
secretsProvider
- used to resolve secrets to decrypt and verify the JWT.decryptionPurpose
- the purpose to use for decrypting the outer JWT.verificationPurpose
- the purpose to use for verifying the signed inner JWT.- Returns:
- a promise to the decrypted and verified JWT or to an exception indicating that either decryption or signature verification failed.
-
decryptAndVerify
public Promise<SignedThenEncryptedJwt,JweDecryptionCheckedException> decryptAndVerify(ValidSecretsReference<? extends CryptoKey, NeverThrowsException> decryptionSecretsReference, ValidSecretsReference<VerificationKey, NeverThrowsException> verificationSecretsReference) Decrypts the outer JWT and then verifies the signature on the inner JWT using supplied valid secrets. If decryption and verification are successful then it returns the decrypted and verified JWT as a promise, otherwise the promise will resolve to aJweDecryptionCheckedException
.- Parameters:
decryptionSecretsReference
- a reference to the valid decryption secrets.verificationSecretsReference
- a reference to the valid verification secrets.- Returns:
- a promise to the decrypted and verified JWT or to an exception indicating that either decryption or signature verification failed.
-
getClaimsSet
Description copied from interface:Jwt
Gets the claims set object for the Jwt, which contains all of the claims (name value pairs) conveyed by the JWT.- Specified by:
getClaimsSet
in interfaceJwt
- Overrides:
getClaimsSet
in classEncryptedJwt
- Returns:
- The JWTs Claims Set.
-
getSignedJwt
Get the signed JWT. Note: you will need to callEncryptedJwt.decrypt(Key)
first.- Returns:
- the nested JWS.
-
copy
Description copied from interface:Jwt
Create a copy of the current JWT.
-
decryptAndVerify(SecretsProvider, Purpose, Purpose)
instead.