de.flexiprovider.api
Class Mac

java.lang.Object
  |
  +--javax.crypto.MacSpi
        |
        +--de.flexiprovider.api.Mac
Direct Known Subclasses:
CBCMac, CMac, HMac, TwoTrackMac

public abstract class Mac
extends javax.crypto.MacSpi

This class implements a "message authentication code" (MAC), a method to ensure the integrity of data transmitted between two parties who share a common secret key.

The best way to describe a MAC is as a keyed one-way hash function, which looks like:

D = MAC(K, M)

where K is the key, M is the message, and D is the resulting digest. One party will usually send the concatenation M || D to the other party, who will then verify D by computing D' in a similar fashion. If D == D', then the message is assumed to be authentic.

Author:
Martin Döring, Johannes Müller

Constructor Summary
Mac()
           
 
Method Summary
abstract  byte[] doFinal()
          Finishes the computation of a MAC and returns the digest.
 byte[] doFinal(byte[] input)
          Finishes the computation of a MAC with a final byte array (or computes a MAC over those bytes only) and returns the digest.
 int doFinal(byte[] output, int outOffset)
          Finishes the computation of a MAC and places the result into the given array.
protected  byte[] engineDoFinal()
           
protected  int engineGetMacLength()
           
protected  void engineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)
           
protected  void engineReset()
           
protected  void engineUpdate(byte input)
           
protected  void engineUpdate(byte[] input, int offset, int len)
           
abstract  int getMacLength()
          Return the MAC length.
 void init(SecretKey key)
          Initialize this MAC with a key and no parameters.
abstract  void init(SecretKey key, AlgorithmParameterSpec params)
          Initialize this MAC with a key and parameters.
abstract  void reset()
          Reset this instance.
abstract  void update(byte input)
          Update the computation with a single byte.
 void update(byte[] input)
          Update the computation with a byte array.
abstract  void update(byte[] input, int offset, int length)
          Update the computation with a portion of a byte array.
 
Methods inherited from class javax.crypto.MacSpi
clone
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mac

public Mac()
Method Detail

engineGetMacLength

protected final int engineGetMacLength()
Overrides:
engineGetMacLength in class javax.crypto.MacSpi

engineInit

protected void engineInit(java.security.Key key,
                          java.security.spec.AlgorithmParameterSpec params)
                   throws java.security.InvalidKeyException,
                          java.security.InvalidAlgorithmParameterException
Overrides:
engineInit in class javax.crypto.MacSpi

engineUpdate

protected final void engineUpdate(byte input)
Overrides:
engineUpdate in class javax.crypto.MacSpi

engineUpdate

protected final void engineUpdate(byte[] input,
                                  int offset,
                                  int len)
Overrides:
engineUpdate in class javax.crypto.MacSpi

engineDoFinal

protected final byte[] engineDoFinal()
Overrides:
engineDoFinal in class javax.crypto.MacSpi

engineReset

protected final void engineReset()
Overrides:
engineReset in class javax.crypto.MacSpi

getMacLength

public abstract int getMacLength()
Return the MAC length. This method is guaranteed to return a sane value only after the MAC has been initialized.
Returns:
the MAC length

init

public final void init(SecretKey key)
                throws InvalidKeyException
Initialize this MAC with a key and no parameters.
Parameters:
key - The key to initialize this instance with.
Throws:
InvalidKeyException - If the key is unacceptable.

init

public abstract void init(SecretKey key,
                          AlgorithmParameterSpec params)
                   throws InvalidAlgorithmParameterException,
                          InvalidKeyException
Initialize this MAC with a key and parameters.
Parameters:
key - The key to initialize this instance with.
params - The algorithm-specific parameters.
Throws:
InvalidAlgorithmParameterException - If the algorithm parameters are unacceptable.
InvalidKeyException - If the key is unacceptable.

update

public abstract void update(byte input)
Update the computation with a single byte.
Parameters:
input - The next byte.

update

public final void update(byte[] input)
Update the computation with a byte array.
Parameters:
input - The next bytes.

update

public abstract void update(byte[] input,
                            int offset,
                            int length)
Update the computation with a portion of a byte array.
Parameters:
input - The next bytes.
offset - The index in input to start.
length - The number of bytes to update.

doFinal

public abstract byte[] doFinal()
Finishes the computation of a MAC and returns the digest.

After this method succeeds, it may be used again as just after a call to init, and can compute another MAC using the same key and parameters.

Returns:
The message authentication code.

doFinal

public final byte[] doFinal(byte[] input)
Finishes the computation of a MAC with a final byte array (or computes a MAC over those bytes only) and returns the digest.

After this method succeeds, it may be used again as just after a call to init, and can compute another MAC using the same key and parameters.

Parameters:
input - The bytes to add.
Returns:
The message authentication code.

doFinal

public final int doFinal(byte[] output,
                         int outOffset)
                  throws ShortBufferException
Finishes the computation of a MAC and places the result into the given array.

After this method succeeds, it may be used again as just after a call to init, and can compute another MAC using the same key and parameters.

Parameters:
output - The destination for the result.
outOffset - The index in the output array to start.
Returns:
the number of bytes stored in output.
Throws:
ShortBufferException - If output is not large enough to hold the result.

reset

public abstract void reset()
Reset this instance. A call to this method returns this instance back to the state it was in just after it was initialized.