Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Mac

public class Mac
extends Object implements Cloneable

java.lang.Object
   ↳ javax.crypto.Mac


This class provides the public API for Message Authentication Code (MAC) algorithms.

Summary

Protected constructors

Mac(MacSpi macSpi, Provider provider, String algorithm)

Creates a new Mac instance.

Public methods

final Object clone()

Clones this Mac instance and the underlying implementation.

final void doFinal(byte[] output, int outOffset)

Computes the digest of this MAC based on the data previously specified in update(byte) calls and stores the digest in the specified output buffer at offset outOffset.

final byte[] doFinal(byte[] input)

Computes the digest of this MAC based on the data previously specified on update(byte) calls and on the final bytes specified by input (or based on those bytes only).

final byte[] doFinal()

Computes the digest of this MAC based on the data previously specified in update(byte) calls.

final String getAlgorithm()

Returns the name of the MAC algorithm.

final static Mac getInstance(String algorithm, String provider)

Creates a new Mac instance that provides the specified MAC algorithm from the specified provider.

final static Mac getInstance(String algorithm, Provider provider)

Creates a new Mac instance that provides the specified MAC algorithm from the specified provider.

final static Mac getInstance(String algorithm)

Creates a new Mac instance that provides the specified MAC algorithm.

final int getMacLength()

Returns the length of this MAC (in bytes).

final Provider getProvider()

Returns the provider of this Mac instance.

final void init(Key key, AlgorithmParameterSpec params)

Initializes this Mac instance with the specified key and algorithm parameters.

final void init(Key key)

Initializes this Mac instance with the specified key.

final void reset()

Resets this Mac instance to its initial state.

final void update(ByteBuffer input)

Updates this Mac instance with the data from the specified buffer, starting at position(), including the next remaining() bytes.

final void update(byte[] input, int offset, int len)

Updates this Mac instance with the data from the specified buffer input from the specified offset and length len.

final void update(byte input)

Updates this Mac instance with the specified byte.

final void update(byte[] input)

Copies the buffer provided as input for further processing.

Inherited methods

From class java.lang.Object

Protected constructors

Mac

Added in API level 1
Mac (MacSpi macSpi, 
                Provider provider, 
                String algorithm)

Creates a new Mac instance.

Parameters
macSpi MacSpi: the implementation delegate.
provider Provider: the implementation provider.
algorithm String: the name of the MAC algorithm.

Public methods

clone

Added in API level 1
Object clone ()

Clones this Mac instance and the underlying implementation.

Returns
Object the cloned instance.
Throws
CloneNotSupportedException if the underlying implementation does not support cloning.

doFinal

Added in API level 1
void doFinal (byte[] output, 
                int outOffset)

Computes the digest of this MAC based on the data previously specified in update(byte) calls and stores the digest in the specified output buffer at offset outOffset.

This Mac instance is reverted to its initial state and can be used to start the next MAC computation with the same parameters or initialized with different parameters.

Parameters
output byte: the output buffer
outOffset int: the offset in the output buffer
Throws
ShortBufferException if the specified output buffer is either too small for the digest to be stored, the specified output buffer is null, or the specified offset is negative or past the length of the output buffer.
IllegalStateException if this MAC is not initialized.

doFinal

Added in API level 1
byte[] doFinal (byte[] input)

Computes the digest of this MAC based on the data previously specified on update(byte) calls and on the final bytes specified by input (or based on those bytes only).

This Mac instance is reverted to its initial state and can be used to start the next MAC computation with the same parameters or initialized with different parameters.

Parameters
input byte: the final bytes.
Returns
byte[] the generated digest.
Throws
IllegalStateException if this MAC is not initialized.

doFinal

Added in API level 1
byte[] doFinal ()

Computes the digest of this MAC based on the data previously specified in update(byte) calls.

This Mac instance is reverted to its initial state and can be used to start the next MAC computation with the same parameters or initialized with different parameters.

Returns
byte[] the generated digest.
Throws
IllegalStateException if this MAC is not initialized.

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the name of the MAC algorithm.

Returns
String the name of the MAC algorithm.

getInstance

Added in API level 1
Mac getInstance (String algorithm, 
                String provider)

Creates a new Mac instance that provides the specified MAC algorithm from the specified provider.

Parameters
algorithm String: the name of the requested MAC algorithm.
provider String: the name of the provider that is providing the algorithm.
Returns
Mac the new Mac instance.
Throws
NoSuchAlgorithmException if the specified algorithm is not provided by the specified provider.
NoSuchProviderException if the specified provider is not available.
IllegalArgumentException if the specified provider name is null or empty.
NullPointerException if algorithm is null (instead of NoSuchAlgorithmException as in 1.4 release).

getInstance

Added in API level 1
Mac getInstance (String algorithm, 
                Provider provider)

Creates a new Mac instance that provides the specified MAC algorithm from the specified provider. The provider supplied does not have to be registered.

Parameters
algorithm String: the name of the requested MAC algorithm.
provider Provider: the provider that is providing the algorithm.
Returns
Mac the new Mac instance.
Throws
NoSuchAlgorithmException if the specified algorithm is not provided by the specified provider.
IllegalArgumentException if provider is null.
NullPointerException if algorithm is null (instead of NoSuchAlgorithmException as in 1.4 release).

getInstance

Added in API level 1
Mac getInstance (String algorithm)

Creates a new Mac instance that provides the specified MAC algorithm.

Parameters
algorithm String: the name of the requested MAC algorithm.
Returns
Mac the new Mac instance.
Throws
NoSuchAlgorithmException if the specified algorithm is not available by any provider.
NullPointerException if algorithm is null (instead of NoSuchAlgorithmException as in 1.4 release).

getMacLength

Added in API level 1
int getMacLength ()

Returns the length of this MAC (in bytes).

Returns
int the length of this MAC (in bytes).

getProvider

Added in API level 1
Provider getProvider ()

Returns the provider of this Mac instance.

Returns
Provider the provider of this Mac instance.

init

Added in API level 1
void init (Key key, 
                AlgorithmParameterSpec params)

Initializes this Mac instance with the specified key and algorithm parameters.

Parameters
key Key: the key to initialize this algorithm.
params AlgorithmParameterSpec: the parameters for this algorithm.
Throws
InvalidKeyException if the specified key cannot be used to initialize this algorithm, or it is null.
InvalidAlgorithmParameterException if the specified parameters cannot be used to initialize this algorithm.

init

Added in API level 1
void init (Key key)

Initializes this Mac instance with the specified key.

Parameters
key Key: the key to initialize this algorithm.
Throws
InvalidKeyException if initialization fails because the provided key is null.
RuntimeException if the specified key cannot be used to initialize this algorithm.

reset

Added in API level 1
void reset ()

Resets this Mac instance to its initial state.

This Mac instance is reverted to its initial state and can be used to start the next MAC computation with the same parameters or initialized with different parameters.

update

Added in API level 1
void update (ByteBuffer input)

Updates this Mac instance with the data from the specified buffer, starting at position(), including the next remaining() bytes.

Parameters
input ByteBuffer: the buffer.
Throws
IllegalStateException if this MAC is not initialized.

update

Added in API level 1
void update (byte[] input, 
                int offset, 
                int len)

Updates this Mac instance with the data from the specified buffer input from the specified offset and length len.

Parameters
input byte: the buffer.
offset int: the offset in the buffer.
len int: the length of the data in the buffer.
Throws
IllegalStateException if this MAC is not initialized.
IllegalArgumentException if offset and len do not specified a valid chunk in input buffer.

update

Added in API level 1
void update (byte input)

Updates this Mac instance with the specified byte.

Parameters
input byte: the byte
Throws
IllegalStateException if this MAC is not initialized.

update

Added in API level 1
void update (byte[] input)

Copies the buffer provided as input for further processing.

Parameters
input byte: the buffer.
Throws
IllegalStateException if this MAC is not initialized.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.