Package org.jasypt.salt
Class RandomSaltGenerator
java.lang.Object
org.jasypt.salt.RandomSaltGenerator
- All Implemented Interfaces:
SaltGenerator
This implementation of SaltGenerator
holds a secure random
generator which can be used for generating random salts for encryption
or digesting.
The algorithm used for random number generation can be configured at instantiation time. If not, the default algorithm will be used.
This class is thread-safe.
- Since:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default algorithm to be used for secure random number generation: set to SHA1PRNG.private final SecureRandom
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of RandomSaltGenerator using the default secure random number generation algorithm.RandomSaltGenerator
(String secureRandomAlgorithm) Creates a new instance of RandomSaltGenerator specifying a secure random number generation algorithm. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
generateSalt
(int lengthBytes) Generate a random salt of the specified length in bytes.boolean
This salt generator needs the salt to be included unencrypted in encryption results, because of its being random.
-
Field Details
-
DEFAULT_SECURE_RANDOM_ALGORITHM
The default algorithm to be used for secure random number generation: set to SHA1PRNG.- See Also:
-
random
-
-
Constructor Details
-
RandomSaltGenerator
public RandomSaltGenerator()Creates a new instance of RandomSaltGenerator using the default secure random number generation algorithm. -
RandomSaltGenerator
Creates a new instance of RandomSaltGenerator specifying a secure random number generation algorithm.- Since:
- 1.5
-
-
Method Details
-
generateSalt
public byte[] generateSalt(int lengthBytes) Generate a random salt of the specified length in bytes.- Specified by:
generateSalt
in interfaceSaltGenerator
- Parameters:
lengthBytes
- length in bytes.- Returns:
- the generated salt.
-
includePlainSaltInEncryptionResults
public boolean includePlainSaltInEncryptionResults()This salt generator needs the salt to be included unencrypted in encryption results, because of its being random. This method will always return true.- Specified by:
includePlainSaltInEncryptionResults
in interfaceSaltGenerator
- Returns:
- true
-