Package com.nimbusds.jose.crypto
Class PasswordBasedEncrypter
- java.lang.Object
-
- 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 ofJWE 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:
- 2021-07-03
- Author:
- Vladimir Dzhuvinov
-
-
Field Summary
Fields Modifier and Type Field Description static int
MIN_RECOMMENDED_ITERATION_COUNT
The minimum recommended iteration count (1000).static int
MIN_SALT_LENGTH
The minimum salt length (8 bytes).-
Fields inherited from class com.nimbusds.jose.crypto.impl.PasswordBasedCryptoProvider
SUPPORTED_ALGORITHMS, SUPPORTED_ENCRYPTION_METHODS
-
-
Constructor Summary
Constructors Constructor Description PasswordBasedEncrypter(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JWECryptoParts
encrypt(JWEHeader header, byte[] clearText)
Encrypts the specified clear text of aJWE object
.int
getIterationCount()
Returns the pseudo-random function (PRF) iteration count.JWEJCAContext
getJCAContext()
Returns the Java Cryptography Architecture (JCA) context.int
getSaltLength()
Returns the length of the generated cryptographic salts.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 com.nimbusds.jose.crypto.impl.PasswordBasedCryptoProvider
getPassword, getPasswordString
-
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 Detail
-
MIN_SALT_LENGTH
public static final int MIN_SALT_LENGTH
The minimum salt length (8 bytes).- See Also:
- Constant Field Values
-
MIN_RECOMMENDED_ITERATION_COUNT
public static final int MIN_RECOMMENDED_ITERATION_COUNT
The minimum recommended iteration count (1000).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PasswordBasedEncrypter
public PasswordBasedEncrypter(byte[] password, int saltLength, int iterationCount)
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
public PasswordBasedEncrypter(String password, int saltLength, int iterationCount)
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 Detail
-
encrypt
public JWECryptoParts encrypt(JWEHeader header, byte[] clearText) throws JOSEException
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
.- 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
public int getSaltLength()
Returns the length of the generated cryptographic salts.- Returns:
- The length of the generated cryptographic salts, in bytes.
-
getIterationCount
public int getIterationCount()
Returns the pseudo-random function (PRF) iteration count.- Returns:
- The iteration count.
-
supportedJWEAlgorithms
public Set<JWEAlgorithm> supportedJWEAlgorithms()
Description copied from interface:JWEProvider
Returns the names of the supported algorithms by the JWE provider instance. These correspond to thealg
JWE header parameter.- Specified by:
supportedJWEAlgorithms
in interfaceJWEProvider
- Returns:
- The supported JWE algorithms, empty set if none.
-
supportedEncryptionMethods
public Set<EncryptionMethod> supportedEncryptionMethods()
Description copied from interface:JWEProvider
Returns the names of the supported encryption methods by the JWE provier. These correspond to theenc
JWE header parameter.- Specified by:
supportedEncryptionMethods
in interfaceJWEProvider
- Returns:
- The supported encryption methods, empty set if none.
-
getJCAContext
public JWEJCAContext getJCAContext()
Description copied from interface:JCAAware
Returns the Java Cryptography Architecture (JCA) context. May be used to set a specific JCA security provider or secure random generator.- Specified by:
getJCAContext
in interfaceJCAAware<JWEJCAContext>
- Returns:
- The JCA context. Not
null
.
-
-