public abstract class Mac
extends java.lang.Object
Mac
object starts out initialized in getInstance(java.lang.String)
method. The secret secretKey must be set with init(java.security.Key)
method, prior to
process any data. The data is processed with update(byte[], int, int)
method.
At any point reset
can be called to reset the digest
to its initialized state. Once all the data to be updated has been updated,
the doFinal()
method should be called to complete
the hash computation and output the result.
The doFinal()
method can be called once for a given number
of updates. After doFinal()
has been called,
the Mac
object is reset to its initialized state.
Therefore, here are three phases to the use of a Mac
object for message authentication:
init(java.security.Key)
)
update(byte[], int, int)
method.doFinal()
method.Constructor and Description |
---|
Mac() |
Modifier and Type | Method and Description |
---|---|
abstract byte[] |
doFinal()
Returns the MAC bytes of all the data consumed and reset the object
to its initialized state.
|
abstract java.lang.String |
getAlgorithm()
Gets the MAC algorithm.
|
static Mac |
getInstance(java.lang.String algorithm)
Generates a
Mac object that implements
the specified digest algorithm. |
abstract int |
getMacLength()
Gets the byte length of the MAC result.
|
abstract void |
init(java.security.Key key)
Initialize this object for hashing.
|
abstract void |
reset()
Resets the
Mac object its initialized state. |
abstract void |
update(byte[] data,
int off,
int len)
Updates the data to be secretKey-hashed, using the specified array of
bytes, starting at the specified offset.
|
public abstract java.lang.String getAlgorithm()
public abstract int getMacLength()
public static Mac getInstance(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
Mac
object that implements
the specified digest algorithm.algorithm
- the standard name of the algorithm requested.
See Appendix A in the
Java Cryptography Architecture API Specification & Reference
for information about standard algorithm names.Mac
object.java.security.NoSuchAlgorithmException
- if the algorithm is
not available in the environment.public abstract void init(java.security.Key key) throws java.security.InvalidKeyException
key
- a raw secret secretKey to use in MAC computation.java.security.InvalidKeyException
- invalid secret keypublic abstract void reset() throws IllegalMacStateException
Mac
object its initialized state. Use init(java.security.Key)
to set a different secretKey.IllegalMacStateException
- Mac
object cannot be
reset to initialized statepublic abstract byte[] doFinal() throws IllegalMacStateException, java.security.DigestException
A call to this method resets the MAC object to the state
it was in when previously initialized for hashing via a
call to init(Key)
. That is, the object is
reset and available to generate another MAC with the same
Key, if desired, via new calls to update
and
doFinal
.
IllegalMacStateException
- if this MAC object is not
initialized properly or if this MAC algorithm is unable to
process the input data provided.java.security.DigestException
- corresponding digest algorithm cannot be
initialized with the current keypublic abstract void update(byte[] data, int off, int len) throws IllegalMacStateException
data
- the array of bytes.off
- the offset to start from in the array of bytes.len
- the number of bytes to use, starting at offset.IllegalMacStateException
- if this MAC object
is not initialized properly.Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.