public class HMac extends BaseMac
The implementation of the HMAC (Keyed-Hash Message Authentication Code).
HMAC can be used in combination with any iterated cryptographic hash function. HMAC also uses a secret key for calculation and verification of the message authentication values. The main goals behind this construction are
References:
Modifier and Type | Field and Description |
---|---|
protected int |
blockSize |
protected byte[] |
ipad |
protected IMessageDigest |
ipadHash |
protected int |
macSize |
protected IMessageDigest |
opadHash |
static java.lang.String |
USE_WITH_PKCS5_V2 |
name, truncatedSize, underlyingHash
MAC_KEY_MATERIAL, TRUNCATED_SIZE
Modifier | Constructor and Description |
---|---|
protected |
HMac(IMessageDigest underlyingHash)
Trivial constructor for use by concrete subclasses.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a clone copy of this instance.
|
byte[] |
digest()
Completes the MAC by performing final operations such as
padding and resetting the instance.
|
void |
init(java.util.Map attributes)
Initialises the algorithm with designated attributes.
|
void |
reset()
Resets the algorithm instance for re-initialisation and use with other
characteristics.
|
boolean |
selfTest()
A basic test.
|
public static final java.lang.String USE_WITH_PKCS5_V2
protected int macSize
protected int blockSize
protected IMessageDigest ipadHash
protected IMessageDigest opadHash
protected byte[] ipad
protected HMac(IMessageDigest underlyingHash)
Trivial constructor for use by concrete subclasses.
underlyingHash
- the underlying hash algorithm instance.public java.lang.Object clone()
IMac
Returns a clone copy of this instance.
public void init(java.util.Map attributes) throws java.security.InvalidKeyException, java.lang.IllegalStateException
IMac
Initialises the algorithm with designated attributes. Permissible names and values are described in the class documentation above.
init
in interface IMac
init
in class BaseMac
attributes
- a set of name-value pairs that describe the desired
future instance behaviour.java.security.InvalidKeyException
- if the key data is invalid.java.lang.IllegalStateException
- if the instance is already initialised.IMac.MAC_KEY_MATERIAL
public void reset()
IMac
Resets the algorithm instance for re-initialisation and use with other characteristics. This method always succeeds.
public byte[] digest()
IMac
Completes the MAC by performing final operations such as padding and resetting the instance.
public boolean selfTest()
IMac
A basic test. Ensures that the MAC of a pre-determined message is equal to a known pre-computed value.
Copyright © 2025. All rights reserved.