Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.crypto.Mac
The best way to describe a MAC is as a keyed one-way hash function, which looks like:
D = MAC(K, M)
where K
is the key, M
is the message,
and D
is the resulting digest. One party will usually
send the concatenation M || D
to the other party, who
will then verify D
by computing D'
in a
similar fashion. If D == D'
, then the message is assumed
to be authentic.
Constructor Summary | |
Method Summary | |
Object |
|
byte[] |
|
byte[] |
|
void |
|
String |
|
static Mac |
|
static Mac |
|
static Mac |
|
int |
|
Provider |
|
void | |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public final Object clone() throws CloneNotSupportedException
Clone this instance, if the underlying implementation supports it.
- Returns:
- A clone of this instance.
- Throws:
CloneNotSupportedException
- If the underlying implementation is not cloneable.
public final byte[] doFinal() throws IllegalStateException
Finishes the computation of a MAC and returns the digest.After this method succeeds, it may be used again as just after a call to
init
, and can compute another MAC using the same key and parameters.
- Returns:
- The message authentication code.
- Throws:
IllegalStateException
- If this instnace has not been initialized.
public final byte[] doFinal(byte[] input) throws IllegalStateException
Finishes the computation of a MAC with a final byte array (or computes a MAC over those bytes only) and returns the digest.After this method succeeds, it may be used again as just after a call to
init
, and can compute another MAC using the same key and parameters.
- Parameters:
input
- The bytes to add.
- Returns:
- The message authentication code.
- Throws:
IllegalStateException
- If this instnace has not been initialized.
public final void doFinal(byte[] output, int outOffset) throws IllegalStateException, ShortBufferException
Finishes the computation of a MAC and places the result into the given array.After this method succeeds, it may be used again as just after a call to
init
, and can compute another MAC using the same key and parameters.
- Parameters:
output
- The destination for the result.outOffset
- The index in the output array to start.
- Throws:
IllegalStateException
- If this instnace has not been initialized.ShortBufferException
- Ifoutput
is not large enough to hold the result.
public final String getAlgorithm()
Returns the name of this MAC algorithm.
- Returns:
- The MAC name.
public static final Mac getInstance(String algorithm) throws NoSuchAlgorithmException
Create an instance of the named algorithm from the first provider with an appropriate implementation.
- Parameters:
algorithm
- The name of the algorithm.
- Returns:
- An appropriate Mac instance, if the specified algorithm is implemented by a provider.
- Throws:
NoSuchAlgorithmException
- If no implementation of the named algorithm is installed.IllegalArgumentException
- ifalgorithm
isnull
or is an empty string.
public static final Mac getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
Create an instance of the named algorithm from the named provider.
- Parameters:
algorithm
- The name of the algorithm.provider
- The name of the provider.
- Returns:
- An appropriate Mac instance, if the specified algorithm is implemented by the named provider.
- Throws:
NoSuchAlgorithmException
- If the named provider has no implementation of the algorithm.NoSuchProviderException
- If the named provider does not exist.IllegalArgumentException
- if eitheralgorithm
orprovider
isnull
, or ifalgorithm
is an empty string.
public static final Mac getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
Create an instance of the named algorithm from a provider.
- Parameters:
algorithm
- The name of the algorithm.provider
- The provider.
- Returns:
- An appropriate Mac instance, if the specified algorithm is implemented by the provider.
- Throws:
NoSuchAlgorithmException
- If the provider has no implementation of the algorithm.IllegalArgumentException
- if eitheralgorithm
orprovider
isnull
, or ifalgorithm
is an empty string.
public final int getMacLength()
Get the size of the MAC. This is the size of the array returned bydoFinal()
anddoFinal(byte[])
, and the minimum number of bytes that must be available in the byte array passed todoFinal(byte[],int)
.
- Returns:
- The MAC length.
public final Provider getProvider()
Get the provider of the underlying implementation.
- Returns:
- The provider.
public final void init(Key key) throws InvalidKeyException
Initialize this MAC with a key and no parameters.
- Parameters:
key
- The key to initialize this instance with.
- Throws:
InvalidKeyException
- If the key is unacceptable.
public final void init(Key key, AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException, InvalidKeyException
Initialize this MAC with a key and parameters.
- Parameters:
key
- The key to initialize this instance with.params
- The algorithm-specific parameters.
- Throws:
InvalidAlgorithmParameterException
- If the algorithm parameters are unacceptable.InvalidKeyException
- If the key is unacceptable.
public final void reset()
Reset this instance. A call to this method returns this instance back to the state it was in just after it was initialized.
public final void update(byte input) throws IllegalStateException
Update the computation with a single byte.
- Parameters:
input
- The next byte.
- Throws:
IllegalStateException
- If this instance has not been initialized.
public final void update(byte[] input) throws IllegalStateException
Update the computation with a byte array.
- Parameters:
input
- The next bytes.
- Throws:
IllegalStateException
- If this instance has not been initialized.
public final void update(byte[] input, int offset, int length) throws IllegalStateException
Update the computation with a portion of a byte array.
- Parameters:
input
- The next bytes.offset
- The index ininput
to start.length
- The number of bytes to update.
- Throws:
IllegalStateException
- If this instance has not been initialized.
public final void update(ByteBuffer buffer)
Update this MAC with the remaining bytes in the given buffer
- Parameters:
buffer
- The input buffer.
- Since:
- 1.5