AXL Software

com.theorem.radserver3.radutil
Class HMAC_MD5

Object
  extended byHMAC_MD5

public final class HMAC_MD5
extends Object

JAVA translation of the hmac_md5() function from RFC 2104.

HMAC: Keyed-Hashing for Message Authentication.

Copyright (C) Michael Lecuyer (1999). All Rights Reserved.

This source code and extensions of it may be used freely as long as the copyright notice above and this paragraph are included in all copies and derivative works.

A notice about the original C code: Copyright (C) The Internet Society (1999). All Rights Reserved.

This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations, except as needed for the purpose of developing Internet standards in which case the procedures for copyrights defined in the Internet Standards process must be followed, or as required to translate it into languages other than English. The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns. This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE."

Version:
2.0
Author:
Michael Lecuyer. Intial coding 1.0 December 26, 1999 Updated to use the Mac interface June 2, 2010

Field Summary
static int DIGEST_LENGTH
          MD5 Hash length - 16.
 
Constructor Summary
HMAC_MD5()
          Defaultl Constructor
HMAC_MD5(byte[] key)
          Defaultl Constructor
 
Method Summary
 byte[] digest()
          Return the digest as calculated by the sign() method.
 byte[] doFinal()
          Finishes the MAC operation.
 byte[] doFinal(byte[] input)
          Finishes the MAC operation.
static HMAC_MD5 get()
          Compatibility with the way this is used by the RADIUS software.
 String getAlgorithm()
          Returns the algorithm name of this Mac object.
 int getMacLength()
          Return the Mac length.
 void init(byte[] key)
          Initializes this Mac object with the given key.
 void init(Key key)
          Initializes this Mac object with the given key.
static void main(String[] arg)
          Run standard tests from the RFC:
 void reset()
          Resets this Mac object.
 String toString()
          Return the digest as a HEX string.
 void update(byte text)
          HMAC_MD5 function.
 void update(byte[] text)
          HMAC_MD5 function.
 void update(byte[] text, int textStart, int textLen)
          HMAC_MD5 function.
 boolean verify(byte[] signature)
          Validate a signature against the current digest.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIGEST_LENGTH

public static final int DIGEST_LENGTH
MD5 Hash length - 16.

See Also:
Constant Field Values
Constructor Detail

HMAC_MD5

public HMAC_MD5()
Defaultl Constructor


HMAC_MD5

public HMAC_MD5(byte[] key)
         throws InvalidKeyException
Defaultl Constructor

Parameters:
key - Key
Method Detail

digest

public byte[] digest()
Return the digest as calculated by the sign() method.

Returns:
The digest.

doFinal

public byte[] doFinal()
Finishes the MAC operation.

Returns:
Mac digest.

doFinal

public byte[] doFinal(byte[] input)
Finishes the MAC operation.

Returns:
Mac digest.

get

public static HMAC_MD5 get()
Compatibility with the way this is used by the RADIUS software.


getAlgorithm

public String getAlgorithm()
Returns the algorithm name of this Mac object.


getMacLength

public int getMacLength()
Return the Mac length.

Returns:
Mac length.

init

public void init(byte[] key)
          throws InvalidKeyException
Initializes this Mac object with the given key.

Parameters:
key - SecretKey.
Throws:
InvalidKeyException

init

public void init(Key key)
          throws InvalidKeyException
Initializes this Mac object with the given key.

Parameters:
key - SecretKey.
Throws:
InvalidKeyException

main

public static void main(String[] arg)
Run standard tests from the RFC:


reset

public void reset()
Resets this Mac object.


toString

public String toString()
Return the digest as a HEX string.

Returns:
a hex representation of the MD5 digest.

update

public void update(byte text)
HMAC_MD5 function.

Parameters:
text - Text to process
Returns:
hash

update

public void update(byte[] text)
HMAC_MD5 function.

Parameters:
text - Text to process
Returns:
hash

update

public void update(byte[] text,
                   int textStart,
                   int textLen)
HMAC_MD5 function.

Parameters:
text - Text to process
textStart - Start position of text in text buffer.
textLen - Length of text to use from text buffer.
Returns:
hash

verify

public boolean verify(byte[] signature)
Validate a signature against the current digest. Compares the hash against the signature.

Parameters:
signature -
Returns:
True if the signature matches the calculated hash.

AXL Software

Submit a bug report or feature request

Copyright 1998-2010 AXL Software PO Box 97, Viola, Delaware 19979, U.S.A. All Rights Reserved.