Class SecureRandom

  • All Implemented Interfaces:
    java.io.Serializable

    public final class SecureRandom
    extends java.security.SecureRandomSpi

    This class provides a cryptographically strong true random number generated based on cryptographic hardware. Note a seed is not necessary for hardware random number generation and if one is passed it is not used. (Allowing the passing of a seed is to allow backwards compatibility with software generated random numbers)

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      SecureRandom()
      Constructs a new instance of this class.
      SecureRandom​(byte[] seed)
      Constructor that requires a seed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] engineGenerateSeed​(int numBytes)
      As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi.
      void engineNextBytes​(byte[] bytes)
      Generates a user-specified number of random bytes.
      void engineSetSeed​(byte[] seed)
      As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi.
      • Methods inherited from class java.security.SecureRandomSpi

        engineGetParameters, engineNextBytes, engineReseed, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • SecureRandom

        public SecureRandom()
        Constructs a new instance of this class.
      • SecureRandom

        public SecureRandom​(byte[] seed)
        Constructor that requires a seed. Note: The seed has no real meaning in hardware and this constructor only exists for compatability with SecureRandomSpi.
        Parameters:
        seed - a series of bytes used as seed
    • Method Detail

      • engineSetSeed

        public void engineSetSeed​(byte[] seed)
        As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi. This method is a no-op whenever called.
        Specified by:
        engineSetSeed in class java.security.SecureRandomSpi
        Parameters:
        seed - a series of bytes used as seed.
      • engineNextBytes

        public void engineNextBytes​(byte[] bytes)
                             throws java.lang.InternalError,
                                    java.lang.RuntimeException
        Generates a user-specified number of random bytes.
        Specified by:
        engineNextBytes in class java.security.SecureRandomSpi
        Parameters:
        bytes - the array to be filled in with random bytes.
        Throws:
        java.lang.InternalError - is thrown when an unexpected error occurs.
        java.lang.RuntimeException - is thrown when a hardware error occurs.
      • engineGenerateSeed

        public byte[] engineGenerateSeed​(int numBytes)
                                  throws java.lang.UnsupportedOperationException
        As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi.
        Specified by:
        engineGenerateSeed in class java.security.SecureRandomSpi
        Throws:
        java.lang.UnsupportedOperationException - is always thrown if this method is invoked.