- All Implemented Interfaces:
- Serializable
SecureRandom class.
 All the abstract methods in this class must be implemented by each service provider who wishes to supply the implementation of a cryptographically strong pseudo-random number generator.
- Implementation Requirements:
- If the SecureRandomSpi(SecureRandomParameters)constructor is overridden in an implementation, it will always be called whenever aSecureRandomis instantiated. Precisely, if an object is instantiated with one ofSecureRandom'sgetInstancemethods without aSecureRandomParametersparameter, the constructor will be called with anullargument and the implementation is responsible for creating its ownSecureRandomParametersparameter for use whenengineGetParameters()is called. If an object is instantiated with one ofSecureRandom'sgetInstancemethods with aSecureRandomParametersargument, the constructor will be called with that argument. TheengineGetParameters()method must not returnnull.Otherwise, if the SecureRandomSpi(SecureRandomParameters)constructor is not overridden in an implementation, theSecureRandomSpi()constructor must be overridden and it will be called if an object is instantiated with one ofSecureRandom'sgetInstancemethods without aSecureRandomParametersargument. Calling one ofSecureRandom'sgetInstancemethods with aSecureRandomParametersargument will never return an instance of this implementation. TheengineGetParameters()method must returnnull.See SecureRandomfor additional details on thread safety. By default, aSecureRandomSpiimplementation is considered to be not safe for use by multiple concurrent threads andSecureRandomwill synchronize access to each of the applicable engine methods (seeSecureRandomfor the list of methods). However, if aSecureRandomSpiimplementation is thread-safe, the service provider attribute "ThreadSafe" should be set to "true" during its registration, as follows:
 orput("SecureRandom.AlgName ThreadSafe", "true");putService(new Service(this, "SecureRandom", "AlgName", className, null, Map.of("ThreadSafe", "true")));SecureRandomwill call the applicable engine methods without any synchronization.
- Since:
- 1.2
- See Also:
- 
Constructor SummaryConstructorsModifierConstructorDescriptionConstructor without a parameter.protectedConstructor with a parameter.
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract byte[]engineGenerateSeed(int numBytes) Returns the given number of seed bytes.protected SecureRandomParametersReturns the effectiveSecureRandomParametersfor thisSecureRandominstance.protected abstract voidengineNextBytes(byte[] bytes) Generates a user-specified number of random bytes.protected voidengineNextBytes(byte[] bytes, SecureRandomParameters params) Generates a user-specified number of random bytes with additional parameters.protected voidengineReseed(SecureRandomParameters params) Reseeds this random object with entropy input read from its entropy source with additional parameters.protected abstract voidengineSetSeed(byte[] seed) Reseeds this random object with the given seed.toString()Returns a Human-readable string representation of thisSecureRandom.
- 
Constructor Details- 
SecureRandomSpipublic SecureRandomSpi()Constructor without a parameter.
- 
SecureRandomSpiConstructor with a parameter.- Parameters:
- params- the- SecureRandomParametersobject. This argument can be- null.
- Throws:
- IllegalArgumentException- if- paramsis unrecognizable or unsupported by this- SecureRandom
- Since:
- 9
 
 
- 
- 
Method Details- 
engineSetSeedprotected abstract void engineSetSeed(byte[] seed) Reseeds this random object with the given seed. The seed supplements, rather than replaces, the existing seed. Thus, repeated calls are guaranteed never to reduce randomness.- Parameters:
- seed- the seed.
 
- 
engineNextBytesprotected abstract void engineNextBytes(byte[] bytes) Generates a user-specified number of random bytes.Some random number generators can only generate a limited amount of random bytes per invocation. If the size of bytesis greater than this limit, the implementation should invoke its generation process multiple times to completely fill the buffer before returning from this method.- Parameters:
- bytes- the array to be filled in with random bytes.
 
- 
engineNextBytesGenerates a user-specified number of random bytes with additional parameters.Some random number generators can only generate a limited amount of random bytes per invocation. If the size of bytesis greater than this limit, the implementation should invoke its generation process multiple times to completely fill the buffer before returning from this method.- Implementation Requirements:
- The default implementation throws
 an UnsupportedOperationException.
- Parameters:
- bytes- the array to be filled in with random bytes
- params- additional parameters
- Throws:
- UnsupportedOperationException- if the implementation has not overridden this method
- IllegalArgumentException- if- paramsis- null, illegal or unsupported by this- SecureRandom
- Since:
- 9
 
- 
engineGenerateSeedprotected abstract byte[] engineGenerateSeed(int numBytes) Returns the given number of seed bytes. This call may be used to seed other random number generators.- Parameters:
- numBytes- the number of seed bytes to generate.
- Returns:
- the seed bytes.
 
- 
engineReseedReseeds this random object with entropy input read from its entropy source with additional parameters.If this method is called by SecureRandom.reseed(),paramswill benull.Do not override this method if the implementation does not support reseeding. - Implementation Requirements:
- The default implementation throws
           an UnsupportedOperationException.
- Parameters:
- params- extra parameters, can be- null.
- Throws:
- UnsupportedOperationException- if the implementation has not overridden this method
- IllegalArgumentException- if- paramsis illegal or unsupported by this- SecureRandom
- Since:
- 9
 
- 
engineGetParametersReturns the effectiveSecureRandomParametersfor thisSecureRandominstance.- Implementation Requirements:
- The default implementation returns null.
- Returns:
- the effective SecureRandomParametersparameters, ornullif no parameters were used.
- Since:
- 9
 
- 
toStringReturns a Human-readable string representation of thisSecureRandom.
 
-