Package org.apache.commons.crypto.random
Class OpenSslCryptoRandom
java.lang.Object
org.apache.commons.crypto.random.OpenSslCryptoRandom
- All Implemented Interfaces:
Closeable
,AutoCloseable
,CryptoRandom
OpenSSL secure random using JNI. This implementation is thread-safe.
If using an Intel chipset with RDRAND, the high-performance hardware random number generator will be used and it's much faster than SecureRandom. If RDRAND is unavailable, default OpenSSL secure random generator will be used. It's still faster and can generate strong random bytes.
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
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
void
close()
OverridesAutoCloseable.close()
.static boolean
Judges whether native library was successfully loaded and initialized.void
nextBytes
(byte[] bytes) Generates a user-specified number of random bytes.
-
Field Details
-
nativeEnabled
private static final boolean nativeEnabled -
initException
-
-
Constructor Details
-
OpenSslCryptoRandom
Constructs aOpenSslCryptoRandom
.- Parameters:
props
- the configuration properties - not used- Throws:
GeneralSecurityException
- if the native library could not be initialized successfully
-
-
Method Details
-
checkNative
- Throws:
GeneralSecurityException
-
isNativeCodeEnabled
public static boolean isNativeCodeEnabled()Judges whether native library was successfully loaded and initialized.- Returns:
- true if library was loaded and initialized
-
close
public void close()OverridesAutoCloseable.close()
. Does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
nextBytes
public void nextBytes(byte[] bytes) Generates a user-specified number of random bytes. It's thread-safe. OverridesRandom
.- Specified by:
nextBytes
in interfaceCryptoRandom
- Parameters:
bytes
- the array to be filled in with random bytes.
-