de.flexiprovider.core.mac
Class HMac

java.lang.Object
  |
  +--javax.crypto.MacSpi
        |
        +--de.flexiprovider.api.Mac
              |
              +--de.flexiprovider.core.mac.HMac
Direct Known Subclasses:
HMac.DHA256, HMac.FORK256, HMac.MD4, HMac.MD5, HMac.RIPEMD128, HMac.RIPEMD160, HMac.RIPEMD256, HMac.RIPEMD320, HMac.SHA1, HMac.SHA224, HMac.SHA256, HMac.SHA384, HMac.SHA512, HMac.Tiger

public class HMac
extends Mac

This class extends the MAC class for providing the functionality of the HMAC(Keyed-Hashing for Message Authentication) algorithm, as specified in RFC 2104.

Any application dealing with MAC computation uses the "getInstance"-method of the MAC class for creating a MAC object.

The FlexiProvider supports HMAC computation based on SHA1, MD5, and RIPEMD160 hash algorithms.


Inner Class Summary
static class HMac.DHA256
           
static class HMac.FORK256
           
static class HMac.MD4
           
static class HMac.MD5
           
static class HMac.RIPEMD128
           
static class HMac.RIPEMD160
           
static class HMac.RIPEMD256
           
static class HMac.RIPEMD320
           
static class HMac.SHA1
           
static class HMac.SHA224
           
static class HMac.SHA256
           
static class HMac.SHA384
           
static class HMac.SHA512
           
static class HMac.Tiger
           
 
Constructor Summary
(package private) HMac(MessageDigest md, int blockSize)
          Creates a new HMac for the specified hash algorithm.
 
Method Summary
 byte[] doFinal()
          Return the computed MAC value.
 int getMacLength()
          Return the MAC length.
 void init(SecretKey key, AlgorithmParameterSpec params)
          Initialize this MAC object with the given key and algorithm parameters (not used).
 void reset()
          Resets this MAC object so that it may be used for further MAC comptations.
 void update(byte input)
          Process the given byte.
 void update(byte[] input, int inOff, int inLen)
          Processes the given number of bytes, supplied in a byte array starting at the given position.
 
Methods inherited from class de.flexiprovider.api.Mac
doFinal, doFinal, engineDoFinal, engineGetMacLength, engineInit, engineReset, engineUpdate, engineUpdate, init, update
 
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

HMac

HMac(MessageDigest md,
     int blockSize)
Creates a new HMac for the specified hash algorithm. This constructor is called by every subclass for specifying the particular hash algorithm to be used for HMac computation.
Parameters:
md - the hash algorithm to use.
blockSize - TODO
Method Detail

getMacLength

public int getMacLength()
Description copied from class: Mac
Return the MAC length. This method is guaranteed to return a sane value only after the MAC has been initialized.
Overrides:
getMacLength in class Mac
Returns:
the length of the calculated MAC value in bytes

init

public void init(SecretKey key,
                 AlgorithmParameterSpec params)
          throws InvalidKeyException
Initialize this MAC object with the given key and algorithm parameters (not used).
Overrides:
init in class Mac
Parameters:
key - the MAC key
params - the algorithm parameters (not used)
Throws:
InvalidKeyException - if the key is not an instance of HMacKey.

update

public void update(byte[] input,
                   int inOff,
                   int inLen)
Processes the given number of bytes, supplied in a byte array starting at the given position.
Overrides:
update in class Mac
Parameters:
input - the byte array containing the input
inOff - the offset where the input starts
inLen - the length of the input

update

public void update(byte input)
Process the given byte.
Overrides:
update in class Mac
Parameters:
input - the byte to be processed

doFinal

public byte[] doFinal()
Return the computed MAC value. After the MAC has been computed, the MAC object is reset and has to be initialized again for further MAC computations.
Overrides:
doFinal in class Mac
Returns:
the computed MAC value

reset

public void reset()
Resets this MAC object so that it may be used for further MAC comptations.
Overrides:
reset in class Mac