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

# MacSpi


`
public


abstract
class
MacSpi
`


`

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


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | javax.crypto.MacSpi |

<br />

*** ** * ** ***

This class defines the *Service Provider Interface* (**SPI** )
for the `Mac` class.
All the abstract methods in this class must be implemented by each
cryptographic service provider who wishes to supply the implementation
of a particular MAC algorithm.

Implementations are free to implement the Cloneable interface.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/javax/crypto/MacSpi#MacSpi()() ` |

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

| ### Protected methods ||
|---|---|
| ` abstract byte[]` | ` https://developer.android.com/reference/javax/crypto/MacSpi#engineDoFinal()() ` Completes the MAC computation and resets the MAC for further use, maintaining the secret key that the MAC was initialized with. |
| ` abstract int` | ` https://developer.android.com/reference/javax/crypto/MacSpi#engineGetMacLength()() ` Returns the length of the MAC in bytes. |
| ` abstract void` | ` https://developer.android.com/reference/javax/crypto/MacSpi#engineInit(java.security.Key,%20java.security.spec.AlgorithmParameterSpec)(https://developer.android.com/reference/java/security/Key key, https://developer.android.com/reference/java/security/spec/AlgorithmParameterSpec params) ` Initializes the MAC with the given (secret) key and algorithm parameters. |
| ` abstract void` | ` https://developer.android.com/reference/javax/crypto/MacSpi#engineReset()() ` Resets the MAC for further use, maintaining the secret key that the MAC was initialized with. |
| ` void` | ` https://developer.android.com/reference/javax/crypto/MacSpi#engineUpdate(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer input) ` Processes `input.remaining()` bytes in the ByteBuffer `input`, starting at `input.position()`. |
| ` abstract void` | ` https://developer.android.com/reference/javax/crypto/MacSpi#engineUpdate(byte)(byte input) ` Processes the given byte. |
| ` abstract void` | ` https://developer.android.com/reference/javax/crypto/MacSpi#engineUpdate(byte[],%20int,%20int)(byte[] input, int offset, int len) ` Processes the first `len` bytes in `input`, starting at `offset` inclusive. |

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

### MacSpi

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

```
public MacSpi ()
```

<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

### engineDoFinal

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

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

Completes the MAC computation and resets the MAC for further use,
maintaining the secret key that the MAC was initialized with.

<br />

| Returns ||
|---|---|
| `byte[]` | the MAC result. <br /> |

### engineGetMacLength

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

```
protected abstract int engineGetMacLength ()
```

Returns the length of the MAC in bytes.

<br />

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

### engineInit

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

```
protected abstract void engineInit (Key key, 
                AlgorithmParameterSpec params)
```

Initializes the MAC with the given (secret) key and algorithm
parameters.

<br />

| Parameters ||
|---|---|
| `key` | `Key`: the (secret) key. <br /> |
| `params` | `AlgorithmParameterSpec`: the algorithm parameters. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/security/InvalidAlgorithmParameterException` | if the given algorithm parameters are inappropriate for this MAC. |
| `https://developer.android.com/reference/java/security/InvalidKeyException` | if the given key is inappropriate for initializing this MAC. |

### engineReset

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

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

Resets the MAC for further use, maintaining the secret key that the
MAC was initialized with.

<br />

### engineUpdate

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

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

Processes `input.remaining()` bytes in the ByteBuffer
`input`, starting at `input.position()`.
Upon return, the buffer's position will be equal to its limit;
its limit will not have changed.

Subclasses should consider overriding this method if they can
process ByteBuffers more efficiently than byte arrays.

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

Processes the given byte.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the input byte to be processed. <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)
```

Processes the first `len` bytes in `input`,
starting at `offset` inclusive.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the input buffer. <br /> |
| `offset` | `int`: the offset in `input` where the input starts. <br /> |
| `len` | `int`: the number of bytes to process. <br /> |