Package com.netscape.cmsutil.util
Class HMACDigest
- java.lang.Object
-
- com.netscape.cmsutil.util.HMACDigest
-
- All Implemented Interfaces:
java.lang.Cloneable
public class HMACDigest extends java.lang.Object implements java.lang.Cloneable
This class implements the HMAC algorithm specified in RFC 2104 using any MessageDigest.- Version:
- $Revision$, $Date$
- Author:
- mikep
- See Also:
MessageDigest
-
-
Constructor Summary
Constructors Constructor Description HMACDigest(java.security.MessageDigest md)
Creates an HMACDigestHMACDigest(java.security.MessageDigest md, byte[] key)
Creates an HMACDigest and initializes the HMAC function with the given key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Clone the HMACDigestbyte[]
digest()
Completes the HMAC computation with the outer pad The digest is reset after this call is made.java.security.MessageDigest
getMessageDigest()
Return the MessageDigest used for this HMACvoid
init(byte[] key)
Initialize the HMAC function The HMAC transform looks like: hash(key XOR opad, hash(key XOR ipad, text)) where key is an n byte key ipad is the byte 0x36 repeated 64 times opad is the byte 0x5c repeated 64 times and text is the data being protected This routine must be called after every reset.void
reset()
Resets the digest for further use.void
update(byte[] input)
Updates the digest using the specified array of bytes.
-
-
-
Field Detail
-
PAD_BYTES
public static final int PAD_BYTES
- See Also:
- Constant Field Values
-
IPAD
public static final int IPAD
- See Also:
- Constant Field Values
-
OPAD
public static final int OPAD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HMACDigest
public HMACDigest(java.security.MessageDigest md)
Creates an HMACDigest- Parameters:
md
- The MessageDigest to be used for the HMAC calculation. It must be clonable.
-
HMACDigest
public HMACDigest(java.security.MessageDigest md, byte[] key)
Creates an HMACDigest and initializes the HMAC function with the given key.- Parameters:
md
- The MessageDigest to be used for the HMAC calculation. It must be clonable.key
- The key value to be used in the HMAC calculation
-
-
Method Detail
-
getMessageDigest
public java.security.MessageDigest getMessageDigest()
Return the MessageDigest used for this HMAC
-
init
public void init(byte[] key)
Initialize the HMAC function The HMAC transform looks like: hash(key XOR opad, hash(key XOR ipad, text)) where key is an n byte key ipad is the byte 0x36 repeated 64 times opad is the byte 0x5c repeated 64 times and text is the data being protected This routine must be called after every reset.- Parameters:
key
- The password used to protect the hash value
-
update
public void update(byte[] input)
Updates the digest using the specified array of bytes.- Parameters:
input
- the array of bytes.
-
digest
public byte[] digest()
Completes the HMAC computation with the outer pad The digest is reset after this call is made.- Returns:
- the array of bytes for the resulting hash value.
-
reset
public void reset()
Resets the digest for further use.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Clone the HMACDigest- Overrides:
clone
in classjava.lang.Object
- Returns:
- a clone if the implementation is cloneable.
- Throws:
java.lang.CloneNotSupportedException
- if this is called on a MessageDigest implementation that does not supportCloneable
.
-
-