org.bouncycastle.crypto.util

## Class JournalingSecureRandom

- java.lang.Object
- - java.util.Random
  - - java.security.SecureRandom
    - - org.bouncycastle.crypto.util.JournalingSecureRandom

- All Implemented Interfaces:
    java.io.Serializable

      public class JournalingSecureRandom
      extends java.security.SecureRandom

  A SecureRandom that maintains a journal of its output. This can be used to recreate an output that was based on randomness For the transcript to be reusable, the order of the requests for randomness during recreation must be consistent with the initial requests and no other sources of randomness may be used.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JournalingSecureRandom()` Default constructor that takes an arbitrary SecureRandom as initial random
    `JournalingSecureRandom(byte[] transcript, java.security.SecureRandom random)` Constructor with a prior transcript.
    `JournalingSecureRandom(java.security.SecureRandom random)` Base constructor - no prior transcript.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clear the internals
    `byte[]` | `getFullTranscript()` Return the full transcript, such as would be needed to create a copy of this JournalingSecureRandom,
    `byte[]` | `getTranscript()` Return the transcript so far,
    `void` | `nextBytes(byte[] bytes)` Fill bytes with random data, journaling the random data before returning or re-use previously used random data, depending on the state of the transcript.
    `void` | `reset()` Resets the index to zero such that the randomness will now be reused

    - ### Methods inherited from class java.security.SecureRandom

      `generateSeed, getAlgorithm, getInstance, getInstance, getInstance, getInstanceStrong, getProvider, getSeed, next, setSeed, setSeed`

    - ### Methods inherited from class java.util.Random

      `doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JournalingSecureRandom

          public JournalingSecureRandom()

      Default constructor that takes an arbitrary SecureRandom as initial random

    - #### JournalingSecureRandom

          public JournalingSecureRandom(java.security.SecureRandom random)

      Base constructor - no prior transcript.
      Parameters:
        `random` - source of randomness we will be journaling.

    - #### JournalingSecureRandom

          public JournalingSecureRandom(byte[] transcript,
                                        java.security.SecureRandom random)

      Constructor with a prior transcript. Both the transcript used and any new randomness are journaled.
      Parameters:
        `transcript` - initial transcript of randomness.
        `random` - source of randomness we will be journaling when the transcript runs out.

  - ### Method Detail

    - #### nextBytes

          public final void nextBytes(byte[] bytes)

      Fill bytes with random data, journaling the random data before returning or re-use previously used random data, depending on the state of the transcript.
      Overrides:
        `nextBytes` in class `java.security.SecureRandom`
      Parameters:
        `bytes` - a block of bytes to be filled with random data.

    - #### clear

          public void clear()

      Clear the internals

    - #### reset

          public void reset()

      Resets the index to zero such that the randomness will now be reused

    - #### getTranscript

          public byte[] getTranscript()

      Return the transcript so far,
      Returns:
        a copy of the randomness produced so far.

    - #### getFullTranscript

          public byte[] getFullTranscript()

      Return the full transcript, such as would be needed to create a copy of this JournalingSecureRandom,
      Returns:
        a copy of the original transcript on construction, plus any randomness added since.