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 intposprivate byte[]reservoirprivate static intRESERVOIR_LENGTHprivate java.io.FileInputStreamstream
-
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 voidclose()OverridesAutoCloseable.close().private voidfillReservoir(int min)Fills the reservoir.voidnextBytes(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_KEYto 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein 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:
nextBytesin interfaceCryptoRandom- Parameters:
bytes- the array to be filled in with random bytes.
-
-