public class Random extends Object
SecureRandom
instance.| Modifier and Type | Field and Description |
|---|---|
static String |
ALGORITHM
The algorithm for the
SecureRandom instance: "SHA1PRNG". |
static int |
ID_BITS
The length of IDs: 256.
|
static int |
SALT_BYTES
The length of salt values: 16.
|
| Constructor and Description |
|---|
Random() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
bytes(int length)
Convenience method to instantiate and populate a byte array of the specified
length.
|
static SecureRandom |
getInstance() |
static String |
id() |
static InputStream |
inputStream(long length)
Convenience method to instantiate an
InputStream of random data of the specified
length. |
static String |
password(int length)
Convenience method to generate a random password.
|
static String |
salt()
Generates a random salt value.
|
public static final int ID_BITS
public static final String ALGORITHM
SecureRandom instance: "SHA1PRNG".public static final int SALT_BYTES
public static SecureRandom getInstance()
SecureRandom instance for
the algorithm "SHA1PRNG". This is a global instance and
is thread-safe. The only consideration is whether thread
contention could be an issue. See
http://stackoverflow.com/questions
/1461568/is-securerandom-thread-safe for more details.public static byte[] bytes(int length)
length - The length of the array.SecureRandom.nextBytes(byte[])public static InputStream inputStream(long length)
InputStream of random data of the specified
length.length - The length of the stream.SecureRandom.nextBytes(byte[])public static String id()
public static String password(int length)
RandomStringUtils.random(int, int, int, boolean, boolean, char[], java.util.Random)
, because the implementation of that method calls
Random.nextInt(), which is not overridden by the
SecureRandom returned by getInstance().
That means passwords wouldn't be generated using cryptographically strong
pseudo random numbers, despite passing a SecureRandom.length - The length of the password to be returned.public static String salt()
Copyright © 2016 Carboni. All rights reserved.