Class ContentCryptoProvider


  • public class ContentCryptoProvider
    extends java.lang.Object
    JWE content encryption / decryption provider.
    Version:
    2022-09-20
    Author:
    Vladimir Dzhuvinov
    • Field Detail

      • SUPPORTED_ENCRYPTION_METHODS

        public static final java.util.Set<EncryptionMethod> SUPPORTED_ENCRYPTION_METHODS
        The supported encryption methods.
      • COMPATIBLE_ENCRYPTION_METHODS

        public static final java.util.Map<java.lang.Integer,​java.util.Set<EncryptionMethod>> COMPATIBLE_ENCRYPTION_METHODS
        The encryption methods compatible with each key size in bits.
    • Constructor Detail

      • ContentCryptoProvider

        public ContentCryptoProvider()
    • Method Detail

      • generateCEK

        public static javax.crypto.SecretKey generateCEK​(EncryptionMethod enc,
                                                         java.security.SecureRandom randomGen)
                                                  throws JOSEException
        Generates a Content Encryption Key (CEK) for the specified JOSE encryption method.
        Parameters:
        enc - The encryption method. Must not be null.
        randomGen - The secure random generator to use. Must not be null.
        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,
                                             javax.crypto.SecretKey cek,
                                             Base64URL encryptedKey,
                                             JWEJCAContext jcaProvider)
                                      throws JOSEException
        Encrypts the specified clear text (content).
        Parameters:
        header - The final JWE header. Must not be null.
        clearText - The clear text to encrypt and optionally compress. Must not be null.
        cek - The Content Encryption Key (CEK). Must not be null.
        encryptedKey - The encrypted CEK, null if not required.
        jcaProvider - The JWE JCA provider specification. Must not be null.
        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,
                                     javax.crypto.SecretKey cek,
                                     JWEJCAContext jcaProvider)
                              throws JOSEException
        Decrypts the specified cipher text.
        Parameters:
        header - The JWE header. Must not be null.
        encryptedKey - The encrypted key, null if not specified.
        iv - The initialisation vector (IV). Must not be null.
        cipherText - The cipher text. Must not be null.
        authTag - The authentication tag. Must not be null.
        cek - The Content Encryption Key (CEK). Must not be null.
        jcaProvider - The JWE JCA provider specification. Must not be null.
        Returns:
        The clear text.
        Throws:
        JOSEException - If decryption failed.