Package org.apache.shiro.crypto
Interface RandomNumberGenerator
-
- All Known Implementing Classes:
SecureRandomNumberGenerator
public interface RandomNumberGeneratorA 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 useSecureRandominstances, but this interface provides a few additional benefits to end-users:- It is an interface rather than the JDK's
SecureRandomconcrete implementation. Implementation details can be customized as necessary based on the application's needs - Default per-instance behavior can be customized on implementations, typically via JavaBeans mutators.
- Perhaps most important for Shiro end-users, tt can more easily be used as a source of cryptographic seed data,
and the data returned is already in a more convenient
ByteSourceformat in case that data needs to behexorbase64-encoded.
RandomNumberGenerator saltGenerator = new
SecureRandomNumberGenerator(); User user = new User(); user.setPasswordSalt(saltGenerator.nextBytes().toBase64()); userDAO.save(user);- Since:
- 1.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description org.apache.shiro.util.ByteSourcenextBytes()Generates a byte array of fixed length filled with random data, often useful for generating salts, initialization vectors or other seed data.org.apache.shiro.util.ByteSourcenextBytes(int numBytes)Generates a byte array of the specified length filled with random data.
-
-
-
Method Detail
-
nextBytes
org.apache.shiro.util.ByteSource nextBytes()
Generates a byte array of fixed length filled with random data, often useful for generating salts, initialization vectors or other seed data. The length is specified as a configuration value on the underlying implementation. If you'd like per-invocation control the number of bytes generated, use thenextBytes(int)method instead.- Returns:
- a byte array of fixed length filled with random data.
- See Also:
nextBytes(int)
-
nextBytes
org.apache.shiro.util.ByteSource nextBytes(int numBytes)
Generates a byte array of the specified length filled with random data.- Parameters:
numBytes- the number of bytes to be populated with random data.- Returns:
- a byte array of the specified length filled with random data.
- See Also:
nextBytes()
-
-