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; 024import javax.crypto.SecretKey; 025 026import com.nimbusds.jose.EncryptionMethod; 027import com.nimbusds.jose.JWEAlgorithm; 028 029 030/** 031 * The base abstract class for RSA encrypters and decrypters of 032 * {@link com.nimbusds.jose.JWEObject JWE objects}. 033 * 034 * <p>Supports the following key management algorithms: 035 * 036 * <ul> 037 * <li>{@link com.nimbusds.jose.JWEAlgorithm#RSA1_5} 038 * <li>{@link com.nimbusds.jose.JWEAlgorithm#RSA_OAEP} 039 * <li>{@link com.nimbusds.jose.JWEAlgorithm#RSA_OAEP_256} 040 * </ul> 041 * 042 * <p>Supports the following content encryption algorithms: 043 * 044 * <ul> 045 * <li>{@link com.nimbusds.jose.EncryptionMethod#A128CBC_HS256} 046 * <li>{@link com.nimbusds.jose.EncryptionMethod#A192CBC_HS384} 047 * <li>{@link com.nimbusds.jose.EncryptionMethod#A256CBC_HS512} 048 * <li>{@link com.nimbusds.jose.EncryptionMethod#A128GCM} 049 * <li>{@link com.nimbusds.jose.EncryptionMethod#A192GCM} 050 * <li>{@link com.nimbusds.jose.EncryptionMethod#A256GCM} 051 * <li>{@link com.nimbusds.jose.EncryptionMethod#A128CBC_HS256_DEPRECATED} 052 * <li>{@link com.nimbusds.jose.EncryptionMethod#A256CBC_HS512_DEPRECATED} 053 * <li>{@link com.nimbusds.jose.EncryptionMethod#XC20P} 054 * </ul> 055 * 056 * @author David Ortiz 057 * @author Vladimir Dzhuvinov 058 * @author Egor Puzanov 059 * @version 2023-03-26 060 */ 061public abstract class RSACryptoProvider extends BaseJWEProvider { 062 063 064 /** 065 * The supported JWE algorithms by the RSA crypto provider class. 066 */ 067 public static final Set<JWEAlgorithm> SUPPORTED_ALGORITHMS; 068 069 070 /** 071 * The supported encryption methods by the RSA crypto provider class. 072 */ 073 public static final Set<EncryptionMethod> SUPPORTED_ENCRYPTION_METHODS = ContentCryptoProvider.SUPPORTED_ENCRYPTION_METHODS; 074 075 076 static { 077 Set<JWEAlgorithm> algs = new LinkedHashSet<>(); 078 algs.add(JWEAlgorithm.RSA1_5); 079 algs.add(JWEAlgorithm.RSA_OAEP); 080 algs.add(JWEAlgorithm.RSA_OAEP_256); 081 algs.add(JWEAlgorithm.RSA_OAEP_384); 082 algs.add(JWEAlgorithm.RSA_OAEP_512); 083 SUPPORTED_ALGORITHMS = Collections.unmodifiableSet(algs); 084 } 085 086 087 /** 088 * Creates a new RSA encryption / decryption provider. 089 * 090 * @param cek The Content Encryption Key (CEK). Must be 128 bits (16 091 * bytes), 192 bits (24 bytes), 256 bits (32 bytes), 384 092 * bits (48 bytes) or 512 bits (64 bytes) long. Must not be 093 * {@code null}. 094 */ 095 protected RSACryptoProvider(final SecretKey cek) { 096 097 super(SUPPORTED_ALGORITHMS, ContentCryptoProvider.SUPPORTED_ENCRYPTION_METHODS, cek); 098 } 099}