|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface RandomNumberGenerator
A component that can generate random number/byte values as needed. Useful in cryptography or security scenarios where random byte arrays are needed, such as for password salts, nonces, initialization vectors and other seeds.
This is essentially the same as aSecureRandom
, and indeed implementations
of this interface will probably all use SecureRandom
instances, but this
interface provides a few additional benefits to end-users:
SecureRandom
concrete implementation. Implementation details
can be customized as necessary based on the application's needsByteSource
format in case that data needs
to be hex
or
base64
-encoded.
RandomNumberGenerator saltGenerator = new SecureRandomNumberGenerator
();
User user = new User();
user.setPasswordSalt(saltGenerator.nextBytes().toBase64());
userDAO.save(user);
Method Summary | |
---|---|
ByteSource |
nextBytes()
Generates a byte array of fixed length filled with random data, often useful for generating salts, initialization vectors or other seed data. |
ByteSource |
nextBytes(int numBytes)
Generates a byte array of the specified length filled with random data. |
Method Detail |
---|
ByteSource nextBytes()
nextBytes(int)
method instead.
nextBytes(int)
ByteSource nextBytes(int numBytes)
numBytes
- the number of bytes to be populated with random data.
nextBytes()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |