org.xbill.DNS.utils
Class HMAC

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

public class HMAC
extends Object

An implementation of the HMAC message authentication code.

Author:
Brian Wellington

Constructor Summary
HMAC(MessageDigest digest, byte[] key)
          Deprecated. won't work with digests using a padding length other than 64; use HMAC(MessageDigest digest, int blockLength, byte [] key) instead.
HMAC(MessageDigest digest, int blockLength, byte[] key)
          Creates a new HMAC instance
HMAC(String digestName, byte[] key)
          Deprecated. won't work with digests using a padding length other than 64; use HMAC(String digestName, int blockLength, byte [] key) instead
HMAC(String digestName, int blockLength, byte[] key)
          Creates a new HMAC instance
 
Method Summary
 void clear()
          Resets the HMAC object for further use
 int digestLength()
          Returns the length of the digest.
 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)
 boolean verify(byte[] signature, boolean truncation_ok)
          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,
            int blockLength,
            byte[] key)
Creates a new HMAC instance

Parameters:
digest - The message digest object.
blockLength - The block length of the message digest.
key - The secret key

HMAC

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

Parameters:
digestName - The name of the message digest function.
blockLength - The block length of the message digest.
key - The secret key.

HMAC

public HMAC(MessageDigest digest,
            byte[] key)
Deprecated. won't work with digests using a padding length other than 64; use HMAC(MessageDigest digest, int blockLength, byte [] key) instead.

Creates a new HMAC instance

Parameters:
digest - The message digest object.
key - The secret key
See Also:
HMAC(MessageDigest digest, int blockLength, byte [] key)

HMAC

public HMAC(String digestName,
            byte[] key)
Deprecated. won't work with digests using a padding length other than 64; use HMAC(String digestName, int blockLength, byte [] key) instead

Creates a new HMAC instance

Parameters:
digestName - The name of the message digest function.
key - The secret key.
See Also:
HMAC(String digestName, int blockLength, byte [] 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 matches, false otherwise

verify

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

Parameters:
signature - The signature to compare against
truncation_ok - If true, the signature may be truncated; only the number of bytes in the provided signature are compared.
Returns:
true if the signature matches, false otherwise

clear

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


digestLength

public int digestLength()
Returns the length of the digest.