private static void configureJwtEncryption(final int encryptionSecretSize, final String encryptionAlgorithm,
                                               final String encryptionMethod, final JwtGenerator g) {
        if (encryptionSecretSize <= 0 || StringUtils.isBlank(encryptionMethod) || StringUtils.isBlank(encryptionAlgorithm)) {
            LOGGER.info("No encryption algorithm or size specified, so the generated JWT will not be encrypted");
            return;
        }

        val encryptionSecret = RandomUtils.randomAlphanumeric(encryptionSecretSize);
        LOGGER.info("==== Encryption Secret ====\n[{}]\n", encryptionSecret);

        val acceptedEncAlgs = Arrays.stream(JWEAlgorithm.class.getDeclaredFields())
            .filter(f -> f.getType().equals(JWEAlgorithm.class))
            .map(Unchecked.function(f -> {
                f.setAccessible(true);
                return ((Algorithm) f.get(null)).getName();
            }))
            .collect(Collectors.joining(","));
        LOGGER.debug("Encryption algorithm: [{}]. Available algorithms are [{}]", encryptionAlgorithm, acceptedEncAlgs);

        val acceptedEncMethods = Arrays.stream(EncryptionMethod.class.getDeclaredFields())
            .filter(f -> f.getType().equals(EncryptionMethod.class))
            .map(Unchecked.function(f -> {
                f.setAccessible(true);
                return ((Algorithm) f.get(null)).getName();
            }))
            .collect(Collectors.joining(","));
        LOGGER.debug("Encryption method: [{}]. Available methods are [{}]", encryptionMethod, acceptedEncMethods);

        val algorithm = JWEAlgorithm.parse(encryptionAlgorithm);
        val encryptionMethodAlg = EncryptionMethod.parse(encryptionMethod);

        if (DirectCryptoProvider.SUPPORTED_ALGORITHMS.contains(algorithm)
            && !DirectCryptoProvider.SUPPORTED_ENCRYPTION_METHODS.contains(encryptionMethodAlg)) {
            LOGGER.warn("Encrypted method [{}] is not supported for algorithm [{}]. Accepted methods are [{}]",
                encryptionMethod, encryptionAlgorithm, DirectCryptoProvider.SUPPORTED_ENCRYPTION_METHODS);
            return;
        }
        if (AESCryptoProvider.SUPPORTED_ALGORITHMS.contains(algorithm)
            && !AESCryptoProvider.SUPPORTED_ENCRYPTION_METHODS.contains(encryptionMethodAlg)) {
            LOGGER.warn("Encrypted method [{}] is not supported for algorithm [{}]. Accepted methods are [{}]",
                encryptionMethod, encryptionAlgorithm, AESCryptoProvider.SUPPORTED_ENCRYPTION_METHODS);
            return;
        }
        g.setEncryptionConfiguration(new SecretEncryptionConfiguration(encryptionSecret, algorithm, encryptionMethodAlg));
    }
Generate.

@param signingSecretSize    the signing secret size
@param encryptionSecretSize the encryption secret size
@param signingAlgorithm     the signing algorithm
@param encryptionAlgorithm  the encryption algorithm
@param encryptionMethod     the encryption algorithm
@param subject              the subject
support/cas-server-support-shell-core/src/main/java/org/apereo/cas/shell/commands/jwt/GenerateJwtCommand.java