Class JournalingSecureRandom

java.lang.Object
java.util.Random
java.security.SecureRandom
org.bouncycastle.crypto.util.JournalingSecureRandom
All Implemented Interfaces:
Serializable, RandomGenerator

public class JournalingSecureRandom extends 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:
  • Constructor Details

    • JournalingSecureRandom

      public JournalingSecureRandom()
      Default constructor that takes an arbitrary SecureRandom as initial random
    • JournalingSecureRandom

      public JournalingSecureRandom(SecureRandom random)
      Base constructor - no prior transcript.
      Parameters:
      random - source of randomness we will be journaling.
    • JournalingSecureRandom

      public JournalingSecureRandom(byte[] transcript, 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 Details

    • 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.
      Specified by:
      nextBytes in interface RandomGenerator
      Overrides:
      nextBytes in class 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.