001/*
002 * nimbus-jose-jwt
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.jose.crypto.impl;
019
020
021import java.util.Collections;
022import java.util.LinkedHashSet;
023import java.util.Set;
024
025import com.nimbusds.jose.EncryptionMethod;
026import com.nimbusds.jose.JWEAlgorithm;
027
028
029/**
030 * The base abstract class for RSA encrypters and decrypters of
031 * {@link com.nimbusds.jose.JWEObject JWE objects}.
032 *
033 * <p>Supports the following key management algorithms:
034 *
035 * <ul>
036 *     <li>{@link com.nimbusds.jose.JWEAlgorithm#RSA1_5}
037 *     <li>{@link com.nimbusds.jose.JWEAlgorithm#RSA_OAEP}
038 *     <li>{@link com.nimbusds.jose.JWEAlgorithm#RSA_OAEP_256}
039 * </ul>
040 *
041 * <p>Supports the following content encryption algorithms:
042 *
043 * <ul>
044 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A128CBC_HS256}
045 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A192CBC_HS384}
046 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A256CBC_HS512}
047 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A128GCM}
048 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A192GCM}
049 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A256GCM}
050 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A128CBC_HS256_DEPRECATED}
051 *     <li>{@link com.nimbusds.jose.EncryptionMethod#A256CBC_HS512_DEPRECATED}
052 *     <li>{@link com.nimbusds.jose.EncryptionMethod#XC20P}
053 * </ul>
054 * 
055 * @author David Ortiz
056 * @author Vladimir Dzhuvinov
057 * @version 2021-09-23
058 */
059public abstract class RSACryptoProvider extends BaseJWEProvider {
060
061
062        /**
063         * The supported JWE algorithms by the RSA crypto provider class.
064         */
065        public static final Set<JWEAlgorithm> SUPPORTED_ALGORITHMS;
066
067
068        /**
069         * The supported encryption methods by the RSA crypto provider class.
070         */
071        public static final Set<EncryptionMethod> SUPPORTED_ENCRYPTION_METHODS = ContentCryptoProvider.SUPPORTED_ENCRYPTION_METHODS;
072
073
074        static {
075                Set<JWEAlgorithm> algs = new LinkedHashSet<>();
076                algs.add(JWEAlgorithm.RSA1_5);
077                algs.add(JWEAlgorithm.RSA_OAEP);
078                algs.add(JWEAlgorithm.RSA_OAEP_256);
079                algs.add(JWEAlgorithm.RSA_OAEP_384);
080                algs.add(JWEAlgorithm.RSA_OAEP_512);
081                SUPPORTED_ALGORITHMS = Collections.unmodifiableSet(algs);
082        }
083
084
085        /**
086         * Creates a new RSA encryption / decryption provider.
087         */
088        protected RSACryptoProvider() {
089
090                super(SUPPORTED_ALGORITHMS, ContentCryptoProvider.SUPPORTED_ENCRYPTION_METHODS);
091        }
092}