SecureRandomSpi (Java SE 9 & JDK 9 ) (original) (raw)
- java.security.SecureRandomSpi
All Implemented Interfaces:
[Serializable](../../java/io/Serializable.html "interface in java.io")
public abstract class SecureRandomSpi
extends Object
implements Serializable
This class defines the Service Provider Interface (SPI) for the 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 a SecureRandom
is instantiated. Precisely, if an object is instantiated with one of SecureRandom
's getInstance
methods_without_ a SecureRandomParameters parameter, the constructor will be called with a null
argument and the implementation is responsible for creating its ownSecureRandomParameters
parameter for use whenengineGetParameters() is called. If an object is instantiated with one of SecureRandom
's getInstance
methods with a SecureRandomParameters
argument, the constructor will be called with that argument. TheengineGetParameters() method must not return null
.
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 of SecureRandom
'sgetInstance
methods without aSecureRandomParameters
argument. Calling one ofSecureRandom
's getInstance
methods with a SecureRandomParameters
argument will never return an instance of this implementation. TheengineGetParameters() method must return null
.
See SecureRandom for additional details on thread safety. By default, a SecureRandomSpi
implementation is considered to be not safe for use by multiple concurrent threads and SecureRandom
will synchronize access to each of the applicable engine methods (see SecureRandom for the list of methods). However, if aSecureRandomSpi
implementation is thread-safe, the service provider attribute "ThreadSafe" should be set to "true" during its registration, as follows:
put("SecureRandom.AlgName ThreadSafe", "true");
or
putService(new Service(this, "SecureRandom", "AlgName", className,
null, Map.of("ThreadSafe", "true")));SecureRandom
will call the applicable engine methods without any synchronization.
Since:
1.2
See Also:
Serialized Form
Constructor Summary
Constructors
Modifier Constructor Description SecureRandomSpi() Constructor without a parameter. protected SecureRandomSpi(SecureRandomParameters params) Constructor with a parameter. Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods
Modifier and Type Method Description protected abstract byte[] engineGenerateSeed(int numBytes) Returns the given number of seed bytes. protected SecureRandomParameters engineGetParameters() Returns the effective SecureRandomParameters for thisSecureRandom instance. protected abstract void engineNextBytes(byte[] bytes) Generates a user-specified number of random bytes. protected void engineNextBytes(byte[] bytes,SecureRandomParameters params) Generates a user-specified number of random bytes with additional parameters. protected void engineReseed(SecureRandomParameters params) Reseeds this random object with entropy input read from its entropy source with additional parameters. protected abstract void engineSetSeed(byte[] seed) Reseeds this random object with the given seed. String toString() Returns a Human-readable string representation of thisSecureRandom. * ### Methods inherited from class java.lang.[Object](../../java/lang/Object.html "class in java.lang") `[clone](../../java/lang/Object.html#clone--), [equals](../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../java/lang/Object.html#finalize--), [getClass](../../java/lang/Object.html#getClass--), [hashCode](../../java/lang/Object.html#hashCode--), [notify](../../java/lang/Object.html#notify--), [notifyAll](../../java/lang/Object.html#notifyAll--), [wait](../../java/lang/Object.html#wait--), [wait](../../java/lang/Object.html#wait-long-), [wait](../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### SecureRandomSpi public SecureRandomSpi() Constructor without a parameter. * #### SecureRandomSpi protected SecureRandomSpi([SecureRandomParameters](../../java/security/SecureRandomParameters.html "interface in java.security") params) Constructor with a parameter. Parameters: `params` \- the [SecureRandomParameters](../../java/security/SecureRandomParameters.html "interface in java.security") object. This argument can be `null`. Throws: `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `params` is unrecognizable or unsupported by this `SecureRandom` Since: 9
Method Detail
* #### engineSetSeed protected 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. * #### engineNextBytes protected 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 `bytes` is 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. * #### engineNextBytes protected void engineNextBytes(byte[] bytes, [SecureRandomParameters](../../java/security/SecureRandomParameters.html "interface in java.security") params) Generates 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 `bytes` is 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](../../java/lang/UnsupportedOperationException.html "class in java.lang"). Parameters: `bytes` \- the array to be filled in with random bytes `params` \- additional parameters Throws: `[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang")` \- if the implementation has not overridden this method `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `params` is `null`, illegal or unsupported by this `SecureRandom` Since: 9 * #### engineGenerateSeed protected 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. * #### engineReseed protected void engineReseed([SecureRandomParameters](../../java/security/SecureRandomParameters.html "interface in java.security") params) Reseeds this random object with entropy input read from its entropy source with additional parameters. If this method is called by [SecureRandom.reseed()](../../java/security/SecureRandom.html#reseed--),`params` will be `null`. Do not override this method if the implementation does not support reseeding. Implementation Requirements: The default implementation throws an [UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang"). Parameters: `params` \- extra parameters, can be `null`. Throws: `[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang")` \- if the implementation has not overridden this method `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `params` is illegal or unsupported by this `SecureRandom` Since: 9 * #### engineGetParameters protected [SecureRandomParameters](../../java/security/SecureRandomParameters.html "interface in java.security") engineGetParameters() Implementation Requirements: The default implementation returns `null`. Returns: the effective [SecureRandomParameters](../../java/security/SecureRandomParameters.html "interface in java.security") parameters, or `null` if no parameters were used. Since: 9 * #### toString public [String](../../java/lang/String.html "class in java.lang") toString() Returns a Human-readable string representation of this`SecureRandom`. Overrides: `[toString](../../java/lang/Object.html#toString--)` in class `[Object](../../java/lang/Object.html "class in java.lang")` Returns: the string representation
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2017, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.