hunt.shiro.crypto.RandomNumberGenerator

Undocumented in source.

Members

Interfaces

RandomNumberGenerator
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. <p/> This is essentially the same as a {@link java.security.SecureRandom SecureRandom}, and indeed implementations of this interface will probably all use {@link java.security.SecureRandom SecureRandom} instances, but this interface provides a few additional benefits to end-users: <ul> <li>It is an interface rather than the JDK's {@code SecureRandom} concrete implementation. Implementation details can be customized as necessary based on the application's needs</li> <li>Default per-instance behavior can be customized on implementations, typically via JavaBeans mutators.</li> <li>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 {@link ByteSource ByteSource} format in case that data needs to be {@link hunt.shiro.util.ByteSource#toHex() hex} or {@link hunt.shiro.util.ByteSource#toBase64() base64}-encoded.</li> </ul> For example, consider the following example generating password salts for new user accounts: <pre> RandomNumberGenerator saltGenerator = new {@link hunt.shiro.crypto.SecureRandomNumberGenerator SecureRandomNumberGenerator}(); User user = new User(); user.setPasswordSalt(saltGenerator.nextBytes().toBase64()); userDAO.save(user); </pre>

Meta