Package org.apache.commons.crypto.random
Class JavaCryptoRandom
java.lang.Object
org.apache.commons.crypto.random.JavaCryptoRandom
- All Implemented Interfaces:
Closeable
,AutoCloseable
,CryptoRandom
A CryptoRandom of Java implementation.
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
OverridesAutoCloseable.close()
.protected int
next
(int numBits) Overrides Random#next().void
nextBytes
(byte[] bytes) OverridesCryptoRandom.nextBytes(byte[])
.
-
Field Details
-
instance
-
-
Constructor Details
-
JavaCryptoRandom
Constructs aJavaCryptoRandom
.- Parameters:
properties
- the configuration properties. Uses the keyCryptoRandomFactory.JAVA_ALGORITHM_KEY
to get the name of the algorithm, with a default ofCryptoRandomFactory.JAVA_ALGORITHM_DEFAULT
-
-
Method Details
-
close
public void close()OverridesAutoCloseable.close()
. ForJavaCryptoRandom
, we don't need to recycle resource.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
next
protected int next(int numBits) Overrides Random#next(). Generates an integer containing the user-specified number of random bits(right justified, with leading zeros).- Parameters:
numBits
- number of random bits to be generated, where 0 <=numBits
<= 32.- Returns:
- int an
int
containing the user-specified number of random bits (right justified, with leading zeros).
-
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.
-