Class OsCryptoRandom

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

    final class OsCryptoRandom
    extends java.lang.Object
    implements CryptoRandom
    A Random implementation that uses random bytes sourced from the operating system.

    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 Detail

      • stream

        private transient java.io.FileInputStream stream
      • reservoir

        private final byte[] reservoir
      • pos

        private int pos
    • Method Detail

      • close

        public void close()
        Overrides AutoCloseable.close(). Closes the OS stream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • fillReservoir

        private void fillReservoir​(int min)
        Fills the reservoir.
        Parameters:
        min - the length.
      • 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.