Package com.nimbusds.jose.crypto.impl
Class ContentCryptoProvider
java.lang.Object
com.nimbusds.jose.crypto.impl.ContentCryptoProvider
JWE content encryption / decryption provider.
- Version:
- 2023-03-21
- Author:
- Vladimir Dzhuvinov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Map<Integer,
Set<EncryptionMethod>> The encryption methods compatible with each key size in bits.static final Set<EncryptionMethod>
The supported encryption methods. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decrypt
(JWEHeader header, byte[] aad, Base64URL encryptedKey, Base64URL iv, Base64URL cipherText, Base64URL authTag, SecretKey cek, JWEJCAContext jcaProvider) Decrypts the specified cipher text.static byte[]
decrypt
(JWEHeader header, Base64URL encryptedKey, Base64URL iv, Base64URL cipherText, Base64URL authTag, SecretKey cek, JWEJCAContext jcaProvider) Decrypts the specified cipher text.static JWECryptoParts
encrypt
(JWEHeader header, byte[] clearText, byte[] aad, SecretKey cek, Base64URL encryptedKey, JWEJCAContext jcaProvider) Encrypts the specified clear text (content).static JWECryptoParts
encrypt
(JWEHeader header, byte[] clearText, SecretKey cek, Base64URL encryptedKey, JWEJCAContext jcaProvider) Encrypts the specified clear text (content).static SecretKey
generateCEK
(EncryptionMethod enc, SecureRandom randomGen) Generates a Content Encryption Key (CEK) for the specified JOSE encryption method.
-
Field Details
-
SUPPORTED_ENCRYPTION_METHODS
The supported encryption methods. -
COMPATIBLE_ENCRYPTION_METHODS
The encryption methods compatible with each key size in bits.
-
-
Constructor Details
-
ContentCryptoProvider
public ContentCryptoProvider()
-
-
Method Details
-
generateCEK
public static SecretKey generateCEK(EncryptionMethod enc, SecureRandom randomGen) throws JOSEException Generates a Content Encryption Key (CEK) for the specified JOSE encryption method.- Parameters:
enc
- The encryption method. Must not benull
.randomGen
- The secure random generator to use. Must not benull
.- Returns:
- The generated CEK (with algorithm "AES").
- Throws:
JOSEException
- If the encryption method is not supported.
-
encrypt
public static JWECryptoParts encrypt(JWEHeader header, byte[] clearText, SecretKey cek, Base64URL encryptedKey, JWEJCAContext jcaProvider) throws JOSEException Encrypts the specified clear text (content).- Parameters:
header
- The final JWE header. Must not benull
.clearText
- The clear text to encrypt and optionally compress. Must not benull
.cek
- The Content Encryption Key (CEK). Must not benull
.encryptedKey
- The encrypted CEK,null
if not required.jcaProvider
- The JWE JCA provider specification. Must not benull
.- Returns:
- The JWE crypto parts.
- Throws:
JOSEException
- If encryption failed.
-
encrypt
public static JWECryptoParts encrypt(JWEHeader header, byte[] clearText, byte[] aad, SecretKey cek, Base64URL encryptedKey, JWEJCAContext jcaProvider) throws JOSEException Encrypts the specified clear text (content).- Parameters:
header
- The final JWE header. Must not benull
.clearText
- The clear text to encrypt and optionally compress. Must not benull
.aad
- The Additional Authenticated Data (AAD), ifnull
the JWE header becomes the AAD.cek
- The Content Encryption Key (CEK). Must not benull
.encryptedKey
- The encrypted CEK,null
if not required.jcaProvider
- The JWE JCA provider specification. Must not benull
.- Returns:
- The JWE crypto parts.
- Throws:
JOSEException
- If encryption failed.
-
decrypt
public static byte[] decrypt(JWEHeader header, Base64URL encryptedKey, Base64URL iv, Base64URL cipherText, Base64URL authTag, SecretKey cek, JWEJCAContext jcaProvider) throws JOSEException Decrypts the specified cipher text.- Parameters:
header
- The JWE header. Must not benull
.encryptedKey
- The encrypted key,null
if not specified.iv
- The initialisation vector (IV). Must not benull
.cipherText
- The cipher text. Must not benull
.authTag
- The authentication tag. Must not benull
.cek
- The Content Encryption Key (CEK). Must not benull
.jcaProvider
- The JWE JCA provider specification. Must not benull
.- Returns:
- The clear text.
- Throws:
JOSEException
- If decryption failed.
-
decrypt
public static byte[] decrypt(JWEHeader header, byte[] aad, Base64URL encryptedKey, Base64URL iv, Base64URL cipherText, Base64URL authTag, SecretKey cek, JWEJCAContext jcaProvider) throws JOSEException Decrypts the specified cipher text.- Parameters:
header
- The JWE header. Must not benull
.aad
- The Additional Authenticated Data (AAD), ifnull
the JWE header becomes the AAD.encryptedKey
- The encrypted key,null
if not specified.iv
- The initialisation vector (IV). Must not benull
.cipherText
- The cipher text. Must not benull
.authTag
- The authentication tag. Must not benull
.cek
- The Content Encryption Key (CEK). Must not benull
.jcaProvider
- The JWE JCA provider specification. Must not benull
.- Returns:
- The clear text.
- Throws:
JOSEException
- If decryption failed.
-