Package org.apache.commons.crypto.random
Class OpenSslCryptoRandom
- java.lang.Object
-
- org.apache.commons.crypto.random.OpenSslCryptoRandom
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,CryptoRandom
final class OpenSslCryptoRandom extends java.lang.Object implements 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
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Throwable
initException
private static boolean
nativeEnabled
-
Constructor Summary
Constructors Constructor Description OpenSslCryptoRandom(java.util.Properties props)
Constructs aOpenSslCryptoRandom
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkNative()
void
close()
OverridesAutoCloseable.close()
.static boolean
isNativeCodeEnabled()
Judges whether native library was successfully loaded and initialized.void
nextBytes(byte[] bytes)
Generates a user-specified number of random bytes.
-
-
-
Constructor Detail
-
OpenSslCryptoRandom
public OpenSslCryptoRandom(java.util.Properties props) throws java.security.GeneralSecurityException
Constructs aOpenSslCryptoRandom
.- Parameters:
props
- the configuration properties - not used- Throws:
java.security.GeneralSecurityException
- if the native library could not be initialized successfully
-
-
Method Detail
-
checkNative
private static void checkNative() throws java.security.GeneralSecurityException
- Throws:
java.security.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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
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.
-
-