Package org.jasypt.iv
Class RandomIvGenerator
- java.lang.Object
-
- org.jasypt.iv.RandomIvGenerator
-
- All Implemented Interfaces:
IvGenerator
public class RandomIvGenerator extends java.lang.Object implements IvGenerator
This implementation of
IvGenerator
holds a secure random generator which can be used for generating random initialization vectors (IV) for encryption.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.9.3
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_SECURE_RANDOM_ALGORITHM
The default algorithm to be used for secure random number generation: set to SHA1PRNG.private java.security.SecureRandom
random
-
Constructor Summary
Constructors Constructor Description RandomIvGenerator()
Creates a new instance of RandomIvGenerator using the default secure random number generation algorithm.RandomIvGenerator(java.lang.String secureRandomAlgorithm)
Creates a new instance of RandomIvGenerator specifying a secure random number generation algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
generateIv(int lengthBytes)
Generate a random IV of the specified length in bytes.boolean
includePlainIvInEncryptionResults()
This IV generator needs the IV to be included unencrypted in encryption results, because of its being random.
-
-
-
Field Detail
-
DEFAULT_SECURE_RANDOM_ALGORITHM
public static final java.lang.String DEFAULT_SECURE_RANDOM_ALGORITHM
The default algorithm to be used for secure random number generation: set to SHA1PRNG.- See Also:
- Constant Field Values
-
random
private final java.security.SecureRandom random
-
-
Constructor Detail
-
RandomIvGenerator
public RandomIvGenerator()
Creates a new instance of RandomIvGenerator using the default secure random number generation algorithm.
-
RandomIvGenerator
public RandomIvGenerator(java.lang.String secureRandomAlgorithm)
Creates a new instance of RandomIvGenerator specifying a secure random number generation algorithm.
-
-
Method Detail
-
generateIv
public byte[] generateIv(int lengthBytes)
Generate a random IV of the specified length in bytes.- Specified by:
generateIv
in interfaceIvGenerator
- Parameters:
lengthBytes
- length in bytes.- Returns:
- the generated IV.
-
includePlainIvInEncryptionResults
public boolean includePlainIvInEncryptionResults()
This IV generator needs the IV to be included unencrypted in encryption results, because of its being random. This method will always return true.- Specified by:
includePlainIvInEncryptionResults
in interfaceIvGenerator
- Returns:
- true
-
-