Package org.apache.commons.crypto.random
Class OsCryptoRandom
java.lang.Object
org.apache.commons.crypto.random.OsCryptoRandom
- All Implemented Interfaces:
Closeable
,AutoCloseable
,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
FieldsModifier and TypeFieldDescriptionprivate int
private final byte[]
private static final int
private FileInputStream
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
OverridesAutoCloseable.close()
.private void
fillReservoir
(int min) Fills the reservoir.void
nextBytes
(byte[] bytes) OverridesCryptoRandom.nextBytes(byte[])
.
-
Field Details
-
RESERVOIR_LENGTH
private static final int RESERVOIR_LENGTH- See Also:
-
stream
-
reservoir
private final byte[] reservoir -
pos
private int pos
-
-
Constructor Details
-
OsCryptoRandom
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 Details
-
close
public void close()OverridesAutoCloseable.close()
. Closes the OS stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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.
-