Package org.apache.commons.crypto.random
Class OsCryptoRandom
- java.lang.Object
-
- org.apache.commons.crypto.random.OsCryptoRandom
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,CryptoRandom
final class OsCryptoRandom extends java.lang.Object implements CryptoRandom
A Random implementation that uses random bytes sourced from the operating system.This class is not public/protected so does not appear in the main Javadoc Please ensure that property use is documented in the enum CryptoRandomFactory.RandomProvider
-
-
Field Summary
Fields Modifier and Type Field Description private int
pos
private byte[]
reservoir
private static int
RESERVOIR_LENGTH
private java.io.FileInputStream
stream
-
Constructor Summary
Constructors Constructor Description OsCryptoRandom(java.util.Properties props)
Constructs aOsCryptoRandom
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
OverridesAutoCloseable.close()
.private void
fillReservoir(int min)
Fills the reservoir.void
nextBytes(byte[] bytes)
OverridesCryptoRandom.nextBytes(byte[])
.
-
-
-
Field Detail
-
RESERVOIR_LENGTH
private static final int RESERVOIR_LENGTH
- See Also:
- Constant Field Values
-
stream
private transient java.io.FileInputStream stream
-
reservoir
private final byte[] reservoir
-
pos
private int pos
-
-
Constructor Detail
-
OsCryptoRandom
public OsCryptoRandom(java.util.Properties props)
Constructs aOsCryptoRandom
.- Parameters:
props
- the configuration properties. UsesCryptoRandomFactory.DEVICE_FILE_PATH_KEY
to determine the path to the random device, default isCryptoRandomFactory.DEVICE_FILE_PATH_DEFAULT
-
-
Method Detail
-
close
public void close()
OverridesAutoCloseable.close()
. Closes the OS stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
fillReservoir
private void fillReservoir(int min)
Fills the reservoir.- Parameters:
min
- the length.
-
nextBytes
public void nextBytes(byte[] bytes)
OverridesCryptoRandom.nextBytes(byte[])
. Generates random bytes and places them into a user-supplied byte array. The number of random bytes produced is equal to the length of the byte array.- Specified by:
nextBytes
in interfaceCryptoRandom
- Parameters:
bytes
- the array to be filled in with random bytes.
-
-