Class JavaCryptoRandom

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, CryptoRandom

    final class JavaCryptoRandom
    extends java.lang.Object
    implements 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 
      Modifier and Type Field Description
      private java.security.SecureRandom instance  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Overrides AutoCloseable.close().
      protected int next​(int numBits)
      Overrides Random#next().
      void nextBytes​(byte[] bytes)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • instance

        private final java.security.SecureRandom instance
    • Method Detail

      • close

        public void close()
        Overrides AutoCloseable.close(). For JavaCryptoRandom, we don't need to recycle resource.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • 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)
        Overrides CryptoRandom.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 interface CryptoRandom
        Parameters:
        bytes - the array to be filled in with random bytes.