Package com.nimbusds.jose.crypto
Class RSAEncrypter
- java.lang.Object
-
- com.nimbusds.jose.crypto.impl.RSACryptoProvider
-
- com.nimbusds.jose.crypto.RSAEncrypter
-
- All Implemented Interfaces:
JCAAware<JWEJCAContext>,JOSEProvider,JWEEncrypter,JWEProvider
@ThreadSafe public class RSAEncrypter extends RSACryptoProvider implements JWEEncrypter
RSA encrypter ofJWE objects. Expects a public RSA key.Encrypts the plain text with a generated AES key (the Content Encryption Key) according to the specified JOSE encryption method, then encrypts the CEK with the public RSA key and returns it alongside the IV, cipher text and authentication tag. See RFC 7518, sections 4.2 and 4.3 for more information.
This class is thread-safe.
Supports the following key management algorithms:
JWEAlgorithm.RSA_OAEP_256JWEAlgorithm.RSA_OAEP_384JWEAlgorithm.RSA_OAEP_512JWEAlgorithm.RSA_OAEP(deprecated)JWEAlgorithm.RSA1_5(deprecated)
Supports the following content encryption algorithms:
- Version:
- 2021-09-26
- Author:
- David Ortiz, Vladimir Dzhuvinov, Jun Yu
-
-
Field Summary
-
Fields inherited from class com.nimbusds.jose.crypto.impl.RSACryptoProvider
SUPPORTED_ALGORITHMS, SUPPORTED_ENCRYPTION_METHODS
-
-
Constructor Summary
Constructors Constructor Description RSAEncrypter(RSAKey rsaJWK)Creates a new RSA encrypter.RSAEncrypter(RSAPublicKey publicKey)Creates a new RSA encrypter.RSAEncrypter(RSAPublicKey publicKey, SecretKey contentEncryptionKey)Creates a new RSA encrypter with an optionally specified content encryption key (CEK).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JWECryptoPartsencrypt(JWEHeader header, byte[] clearText)Encrypts the specified clear text of aJWE object.JWEJCAContextgetJCAContext()Returns the Java Cryptography Architecture (JCA) context.RSAPublicKeygetPublicKey()Gets the public RSA key.Set<EncryptionMethod>supportedEncryptionMethods()Returns the names of the supported encryption methods by the JWE provier.Set<JWEAlgorithm>supportedJWEAlgorithms()Returns the names of the supported algorithms by the JWE provider instance.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.nimbusds.jose.jca.JCAAware
getJCAContext
-
Methods inherited from interface com.nimbusds.jose.JWEProvider
supportedEncryptionMethods, supportedJWEAlgorithms
-
-
-
-
Constructor Detail
-
RSAEncrypter
public RSAEncrypter(RSAPublicKey publicKey)
Creates a new RSA encrypter.- Parameters:
publicKey- The public RSA key. Must not benull.
-
RSAEncrypter
public RSAEncrypter(RSAKey rsaJWK) throws JOSEException
Creates a new RSA encrypter.- Parameters:
rsaJWK- The RSA JSON Web Key (JWK). Must not benull.- Throws:
JOSEException- If the RSA JWK extraction failed.
-
RSAEncrypter
public RSAEncrypter(RSAPublicKey publicKey, SecretKey contentEncryptionKey)
Creates a new RSA encrypter with an optionally specified content encryption key (CEK).- Parameters:
publicKey- The public RSA key. Must not benull.contentEncryptionKey- The content encryption key (CEK) to use. If specified its algorithm must be "AES" or "ChaCha20" and its length must match the expected for the JWE encryption method ("enc"). Ifnulla CEK will be generated for each JWE.
-
-
Method Detail
-
getPublicKey
public RSAPublicKey getPublicKey()
Gets the public RSA key.- Returns:
- The public RSA key.
-
encrypt
public JWECryptoParts encrypt(JWEHeader header, byte[] clearText) throws JOSEException
Description copied from interface:JWEEncrypterEncrypts the specified clear text of aJWE object.- Specified by:
encryptin interfaceJWEEncrypter- Parameters:
header- The JSON Web Encryption (JWE) header. Must specify a supported JWE algorithm and method. Must not benull.clearText- The clear text to encrypt. Must not benull.- Returns:
- The resulting JWE crypto parts.
- Throws:
JOSEException- If the JWE algorithm or method is not supported or if encryption failed for some other internal reason.
-
supportedJWEAlgorithms
public Set<JWEAlgorithm> supportedJWEAlgorithms()
Description copied from interface:JWEProviderReturns the names of the supported algorithms by the JWE provider instance. These correspond to thealgJWE header parameter.- Specified by:
supportedJWEAlgorithmsin interfaceJWEProvider- Returns:
- The supported JWE algorithms, empty set if none.
-
supportedEncryptionMethods
public Set<EncryptionMethod> supportedEncryptionMethods()
Description copied from interface:JWEProviderReturns the names of the supported encryption methods by the JWE provier. These correspond to theencJWE header parameter.- Specified by:
supportedEncryptionMethodsin interfaceJWEProvider- Returns:
- The supported encryption methods, empty set if none.
-
getJCAContext
public JWEJCAContext getJCAContext()
Description copied from interface:JCAAwareReturns the Java Cryptography Architecture (JCA) context. May be used to set a specific JCA security provider or secure random generator.- Specified by:
getJCAContextin interfaceJCAAware<JWEJCAContext>- Returns:
- The JCA context. Not
null.
-
-