Package com.nimbusds.jose.crypto
Class PasswordBasedEncrypter
java.lang.Object
com.nimbusds.jose.crypto.impl.BaseJWEProvider
com.nimbusds.jose.crypto.impl.PasswordBasedCryptoProvider
com.nimbusds.jose.crypto.PasswordBasedEncrypter
- All Implemented Interfaces:
JCAAware<JWEJCAContext>
,JOSEProvider
,JWEEncrypter
,JWEProvider
@ThreadSafe
public class PasswordBasedEncrypter
extends PasswordBasedCryptoProvider
implements JWEEncrypter
Password-based encrypter of
JWE objects
.
Expects a password.
See RFC 7518 section 4.8 for more information.
This class is thread-safe.
Supports the following key management algorithms:
Supports the following content encryption algorithms:
- Version:
- 2023-09-10
- Author:
- Vladimir Dzhuvinov, Egor Puzanov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The minimum recommended iteration count (1000).static final int
The minimum salt length (8 bytes).Fields inherited from class com.nimbusds.jose.crypto.impl.PasswordBasedCryptoProvider
SUPPORTED_ALGORITHMS, SUPPORTED_ENCRYPTION_METHODS
-
Constructor Summary
ConstructorsConstructorDescriptionPasswordBasedEncrypter
(byte[] password, int saltLength, int iterationCount) Creates a new password-based encrypter.PasswordBasedEncrypter
(String password, int saltLength, int iterationCount) Creates a new password-based encrypter. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Encrypts the specified clear text of aJWE object
.int
Returns the pseudo-random function (PRF) iteration count.int
Returns the length of the generated cryptographic salts.Methods inherited from class com.nimbusds.jose.crypto.impl.PasswordBasedCryptoProvider
getPassword, getPasswordString
Methods inherited from class com.nimbusds.jose.crypto.impl.BaseJWEProvider
getCEK, getJCAContext, isCEKProvided, supportedEncryptionMethods, supportedJWEAlgorithms
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
-
Field Details
-
MIN_SALT_LENGTH
The minimum salt length (8 bytes).- See Also:
-
MIN_RECOMMENDED_ITERATION_COUNT
The minimum recommended iteration count (1000).- See Also:
-
-
Constructor Details
-
PasswordBasedEncrypter
Creates a new password-based encrypter.- Parameters:
password
- The password bytes. Must not be empty ornull
.saltLength
- The length of the generated cryptographic salts, in bytes. Must be at least 8 bytes.iterationCount
- The pseudo-random function (PRF) iteration count. Must be at least 1000.
-
PasswordBasedEncrypter
Creates a new password-based encrypter.- Parameters:
password
- The password, as a UTF-8 encoded string. Must not be empty ornull
.saltLength
- The length of the generated cryptographic salts, in bytes. Must be at least 8 bytes.iterationCount
- The pseudo-random function (PRF) iteration count. Must be at least 1000.
-
-
Method Details
-
encrypt
Deprecated.Encrypts the specified clear text of aJWE object
.- 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.
-
encrypt
Description copied from interface:JWEEncrypter
Encrypts the specified clear text of aJWE object
.- Specified by:
encrypt
in 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
.aad
- The additional authenticated data. 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.
-
getSaltLength
Returns the length of the generated cryptographic salts.- Returns:
- The length of the generated cryptographic salts, in bytes.
-
getIterationCount
Returns the pseudo-random function (PRF) iteration count.- Returns:
- The iteration count.
-