public interface RandomNumberGenerator
SecureRandom, 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);
| Modifier and Type | Method and Description |
|---|---|
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.
|
ByteSource nextBytes()
nextBytes(int) method instead.nextBytes(int)ByteSource nextBytes(int numBytes)
numBytes - the number of bytes to be populated with random data.nextBytes()Copyright © 2004-2016 The Apache Software Foundation. All Rights Reserved.