public class HMACDigest
extends java.lang.Object
implements java.lang.Cloneable
MessageDigest
Modifier and Type | Field and Description |
---|---|
static int |
IPAD |
static int |
OPAD |
static int |
PAD_BYTES |
Constructor and Description |
---|
HMACDigest(java.security.MessageDigest md)
Creates an HMACDigest
|
HMACDigest(java.security.MessageDigest md,
byte[] key)
Creates an HMACDigest and initializes the HMAC function
with the given key.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clone the HMACDigest
|
byte[] |
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 HMAC
|
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.
|
void |
reset()
Resets the digest for further use.
|
void |
update(byte[] input)
Updates the digest using the specified array of bytes.
|
public static final int PAD_BYTES
public static final int IPAD
public static final int OPAD
public HMACDigest(java.security.MessageDigest md)
md
- The MessageDigest to be used for the HMAC calculation. It
must be clonable.public HMACDigest(java.security.MessageDigest md, byte[] key)
md
- The MessageDigest to be used for the HMAC calculation. It
must be clonable.key
- The key value to be used in the HMAC calculationpublic java.security.MessageDigest getMessageDigest()
public void init(byte[] key)
key
- The password used to protect the hash valuepublic void update(byte[] input)
input
- the array of bytes.public byte[] digest()
public void reset()
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if this is called on a
MessageDigest implementation that does not support Cloneable
.