Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/java/security/SecureRandomSpi#pubctors) \| [Protected Ctors](https://developer.android.com/reference/java/security/SecureRandomSpi#proctors) \| [Methods](https://developer.android.com/reference/java/security/SecureRandomSpi#pubmethods) \| [Protected Methods](https://developer.android.com/reference/java/security/SecureRandomSpi#promethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/SecureRandomSpi#inhmethods)

# SecureRandomSpi


`
public


abstract
class
SecureRandomSpi
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/io/Serializable


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.security.SecureRandomSpi |

<br />

*** ** * ** ***

This class defines the *Service Provider Interface* (**SPI** )
for the `https://developer.android.com/reference/java/security/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.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/SecureRandomSpi#SecureRandomSpi()() ` Constructor without a parameter. |

| ### Protected constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/SecureRandomSpi#SecureRandomSpi(java.security.SecureRandomParameters)(https://developer.android.com/reference/java/security/SecureRandomParameters params) ` Constructor with a parameter. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/security/SecureRandomSpi#toString()() ` Returns a Human-readable string representation of this `SecureRandom`. |

| ### Protected methods ||
|---|---|
| ` abstract byte[]` | ` https://developer.android.com/reference/java/security/SecureRandomSpi#engineGenerateSeed(int)(int numBytes) ` Returns the given number of seed bytes. |
| ` https://developer.android.com/reference/java/security/SecureRandomParameters` | ` https://developer.android.com/reference/java/security/SecureRandomSpi#engineGetParameters()() ` Returns the effective `https://developer.android.com/reference/java/security/SecureRandomParameters` for this `SecureRandom` instance. |
| ` void` | ` https://developer.android.com/reference/java/security/SecureRandomSpi#engineNextBytes(byte[],%20java.security.SecureRandomParameters)(byte[] bytes, https://developer.android.com/reference/java/security/SecureRandomParameters params) ` Generates a user-specified number of random bytes with additional parameters. |
| ` abstract void` | ` https://developer.android.com/reference/java/security/SecureRandomSpi#engineNextBytes(byte[])(byte[] bytes) ` Generates a user-specified number of random bytes. |
| ` void` | ` https://developer.android.com/reference/java/security/SecureRandomSpi#engineReseed(java.security.SecureRandomParameters)(https://developer.android.com/reference/java/security/SecureRandomParameters params) ` Reseeds this random object with entropy input read from its entropy source with additional parameters. |
| ` abstract void` | ` https://developer.android.com/reference/java/security/SecureRandomSpi#engineSetSeed(byte[])(byte[] seed) ` Reseeds this random object with the given seed. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### SecureRandomSpi

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public SecureRandomSpi ()
```

Constructor without a parameter.

<br />

## Protected constructors

### SecureRandomSpi

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected SecureRandomSpi (SecureRandomParameters params)
```

Constructor with a parameter.

<br />

| Parameters ||
|---|---|
| `params` | `SecureRandomParameters`: the `https://developer.android.com/reference/java/security/SecureRandomParameters` object. This argument can be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `params` is unrecognizable or unsupported by this `SecureRandom` |

## Public methods

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a Human-readable string representation of this
`SecureRandom`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the string representation <br /> |

## Protected methods

### engineGenerateSeed

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected abstract byte[] engineGenerateSeed (int numBytes)
```

Returns the given number of seed bytes. This call may be used to
seed other random number generators.

<br />

| Parameters ||
|---|---|
| `numBytes` | `int`: the number of seed bytes to generate. <br /> |

| Returns ||
|---|---|
| `byte[]` | the seed bytes. <br /> |

### engineGetParameters

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected SecureRandomParameters engineGetParameters ()
```

Returns the effective `https://developer.android.com/reference/java/security/SecureRandomParameters` for this
`SecureRandom` instance.

<br />

##### Implementation Requirements:

- The default implementation returns `null`.

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/SecureRandomParameters` | the effective `https://developer.android.com/reference/java/security/SecureRandomParameters` parameters, or `null` if no parameters were used. <br /> |

### engineNextBytes

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void engineNextBytes (byte[] bytes, 
                SecureRandomParameters 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.

<br />

##### Implementation Requirements:

- The default implementation throws an `https://developer.android.com/reference/java/lang/UnsupportedOperationException`.

| Parameters ||
|---|---|
| `bytes` | `byte`: the array to be filled in with random bytes <br /> |
| `params` | `SecureRandomParameters`: additional parameters <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `params` is `null`, illegal or unsupported by this `SecureRandom` |
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException` | if the implementation has not overridden this method |

### engineNextBytes

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `bytes` | `byte`: the array to be filled in with random bytes. <br /> |

### engineReseed

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void engineReseed (SecureRandomParameters params)
```

Reseeds this random object with entropy input read from its
entropy source with additional parameters.


If this method is called by `https://developer.android.com/reference/java/security/SecureRandom#reseed()`,
`params` will be `null`.


Do not override this method if the implementation does not
support reseeding.

<br />

##### Implementation Requirements:

- The default implementation throws an `https://developer.android.com/reference/java/lang/UnsupportedOperationException`.

| Parameters ||
|---|---|
| `params` | `SecureRandomParameters`: extra parameters, can be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `params` is illegal or unsupported by this `SecureRandom` |
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException` | if the implementation has not overridden this method |

### engineSetSeed

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `seed` | `byte`: the seed. <br /> |