org.xbill.DNS.utils
Class HMAC

java.lang.Object
  extended by org.xbill.DNS.utils.HMAC

public class HMAC
extends Object

A pure java implementation of the HMAC-MD5 secure hash algorithm

Author:
Brian Wellington

Constructor Summary
HMAC(MessageDigest digest, byte[] key)
          Creates a new HMAC instance
HMAC(String digestName, byte[] key)
          Creates a new HMAC instance
 
Method Summary
 void clear()
          Resets the HMAC object for further use
 byte[] sign()
          Signs the data (computes the secure hash)
 void update(byte[] b)
          Adds data to the current hash
 void update(byte[] b, int offset, int length)
          Adds data to the current hash
 boolean verify(byte[] signature)
          Verifies the data (computes the secure hash and compares it to the input)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HMAC

public HMAC(MessageDigest digest,
            byte[] key)
Creates a new HMAC instance

Parameters:
digest - The message digest object.
key - The secret key

HMAC

public HMAC(String digestName,
            byte[] key)
Creates a new HMAC instance

Parameters:
digestName - The name of the message digest function.
key - The secret key.
Method Detail

update

public void update(byte[] b,
                   int offset,
                   int length)
Adds data to the current hash

Parameters:
b - The data
offset - The index at which to start adding to the hash
length - The number of bytes to hash

update

public void update(byte[] b)
Adds data to the current hash

Parameters:
b - The data

sign

public byte[] sign()
Signs the data (computes the secure hash)

Returns:
An array with the signature

verify

public boolean verify(byte[] signature)
Verifies the data (computes the secure hash and compares it to the input)

Parameters:
signature - The signature to compare against
Returns:
true if the signature matched, false otherwise

clear

public void clear()
Resets the HMAC object for further use