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/MessageDigestSpi#pubctors) \| [Methods](https://developer.android.com/reference/java/security/MessageDigestSpi#pubmethods) \| [Protected Methods](https://developer.android.com/reference/java/security/MessageDigestSpi#promethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/MessageDigestSpi#inhmethods)

# MessageDigestSpi


`
public


abstract
class
MessageDigestSpi
`


`

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


`

`


`

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

|---|
| Known direct subclasses [MessageDigest](https://developer.android.com/reference/java/security/MessageDigest) |---|---| | [MessageDigest](https://developer.android.com/reference/java/security/MessageDigest) | This MessageDigest class provides applications the functionality of a message digest algorithm, such as SHA-1 or SHA-256. | |

<br />

*** ** * ** ***

This class defines the *Service Provider Interface* (**SPI** )
for the `MessageDigest` class, which provides the functionality
of a message digest algorithm, such as MD5 or SHA. Message digests are
secure one-way hash functions that take arbitrary-sized data and output a
fixed-length hash value.

All the abstract methods in this class must be implemented by a
cryptographic service provider who wishes to supply the implementation
of a particular message digest algorithm.

Implementations are free to implement the Cloneable interface.
**See also:**

- `https://developer.android.com/reference/java/security/MessageDigest`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/MessageDigestSpi#MessageDigestSpi()() ` |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#clone()() ` Returns a clone if the implementation is cloneable. |

| ### Protected methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#engineDigest(byte[],%20int,%20int)(byte[] buf, int offset, int len) ` Completes the hash computation by performing final operations such as padding. |
| ` abstract byte[]` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#engineDigest()() ` Completes the hash computation by performing final operations such as padding. |
| ` int` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#engineGetDigestLength()() ` Returns the digest length in bytes. |
| ` abstract void` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#engineReset()() ` Resets the digest for further use. |
| ` void` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#engineUpdate(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer input) ` Update the digest using the specified ByteBuffer. |
| ` abstract void` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#engineUpdate(byte)(byte input) ` Updates the digest using the specified byte. |
| ` abstract void` | ` https://developer.android.com/reference/java/security/MessageDigestSpi#engineUpdate(byte[],%20int,%20int)(byte[] input, int offset, int len) ` Updates the digest using the specified array of bytes, starting at the specified offset. |

| ### 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

### MessageDigestSpi

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

```
public MessageDigestSpi ()
```

<br />

<br />

## Public methods

### clone

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

```
public Object clone ()
```

Returns a clone if the implementation is cloneable.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | a clone if the implementation is cloneable. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/CloneNotSupportedException` | if this is called on an implementation that does not support `Cloneable`. |

## Protected methods

### engineDigest

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

```
protected int engineDigest (byte[] buf, 
                int offset, 
                int len)
```

Completes the hash computation by performing final
operations such as padding. Once `engineDigest` has
been called, the engine should be reset (see
`https://developer.android.com/reference/java/security/MessageDigestSpi#engineReset()`).
Resetting is the responsibility of the
engine implementor.

This method should be abstract, but we leave it concrete for
binary compatibility. Knowledgeable providers should override this
method.

<br />

| Parameters ||
|---|---|
| `buf` | `byte`: the output buffer in which to store the digest <br /> |
| `offset` | `int`: offset to start from in the output buffer <br /> |
| `len` | `int`: number of bytes within buf allotted for the digest. Both this default implementation and the SUN provider do not return partial digests. The presence of this parameter is solely for consistency in our API's. If the value of this parameter is less than the actual digest length, the method will throw a DigestException. This parameter is ignored if its value is greater than or equal to the actual digest length. <br /> |

| Returns ||
|---|---|
| `int` | the length of the digest stored in the output buffer. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/security/DigestException` | if an error occurs. |

### engineDigest

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

```
protected abstract byte[] engineDigest ()
```

Completes the hash computation by performing final
operations such as padding. Once `engineDigest` has
been called, the engine should be reset (see
`https://developer.android.com/reference/java/security/MessageDigestSpi#engineReset()`).
Resetting is the responsibility of the
engine implementor.

<br />

| Returns ||
|---|---|
| `byte[]` | the array of bytes for the resulting hash value. <br /> |

### engineGetDigestLength

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

```
protected int engineGetDigestLength ()
```

Returns the digest length in bytes.

This concrete method has been added to this previously-defined
abstract class. (For backwards compatibility, it cannot be abstract.)

The default behavior is to return 0.

This method may be overridden by a provider to return the digest
length.

<br />

| Returns ||
|---|---|
| `int` | the digest length in bytes. <br /> |

### engineReset

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

```
protected abstract void engineReset ()
```

Resets the digest for further use.

<br />

### engineUpdate

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

```
protected void engineUpdate (ByteBuffer input)
```

Update the digest using the specified ByteBuffer. The digest is
updated using the `input.remaining()` bytes starting
at `input.position()`.
Upon return, the buffer's position will be equal to its limit;
its limit will not have changed.

<br />

| Parameters ||
|---|---|
| `input` | `ByteBuffer`: the ByteBuffer <br /> |

### engineUpdate

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

```
protected abstract void engineUpdate (byte input)
```

Updates the digest using the specified byte.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the byte to use for the update. <br /> |

### engineUpdate

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

```
protected abstract void engineUpdate (byte[] input, 
                int offset, 
                int len)
```

Updates the digest using the specified array of bytes,
starting at the specified offset.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the array of bytes to use for the update. <br /> |
| `offset` | `int`: the offset to start from in the array of bytes. <br /> |
| `len` | `int`: the number of bytes to use, starting at `offset`. <br /> |