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 intprivate final byte[]private static final intprivate FileInputStream -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()OverridesAutoCloseable.close().private voidfillReservoir(int min) Fills the reservoir.voidnextBytes(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_KEYto 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:
closein interfaceAutoCloseable- Specified by:
closein 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:
nextBytesin interfaceCryptoRandom- Parameters:
bytes- the array to be filled in with random bytes.
-