Class OpenSslCryptoRandom

java.lang.Object
org.apache.commons.crypto.random.OpenSslCryptoRandom
All Implemented Interfaces:
Closeable, AutoCloseable, CryptoRandom

final class OpenSslCryptoRandom extends 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

See Also:
  • Field Details

    • nativeEnabled

      private static final boolean nativeEnabled
    • initException

      private static final Throwable initException
  • Constructor Details

  • Method Details

    • checkNative

      private static void checkNative() throws GeneralSecurityException
      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()
      Overrides AutoCloseable.close(). Does nothing.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • nextBytes

      public void nextBytes(byte[] bytes)
      Generates a user-specified number of random bytes. It's thread-safe. Overrides Random.
      Specified by:
      nextBytes in interface CryptoRandom
      Parameters:
      bytes - the array to be filled in with random bytes.