javax.crypto
Class Mac
- Cloneable
This class implements a "message authentication code" (MAC), a method
to ensure the integrity of data transmitted between two parties who
share a common secret key.
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.
Object | clone() - Clone this instance, if the underlying implementation supports it.
|
byte[] | doFinal() - Finishes the computation of a MAC and returns the digest.
|
byte[] | doFinal(byte[] input) - Finishes the computation of a MAC with a final byte array (or
computes a MAC over those bytes only) and returns the digest.
|
void | doFinal(byte[] output, int outOffset) - Finishes the computation of a MAC and places the result into the
given array.
|
String | getAlgorithm() - Returns the name of this MAC algorithm.
|
static Mac | getInstance(String algorithm) - Create an instance of the named algorithm from the first provider with an
appropriate implementation.
|
static Mac | getInstance(String algorithm, String provider) - Create an instance of the named algorithm from the named provider.
|
static Mac | getInstance(String algorithm, Provider provider) - Create an instance of the named algorithm from a provider.
|
int | getMacLength() - Get the size of the MAC.
|
Provider | getProvider() - Get the provider of the underlying implementation.
|
void | init(Key key) - Initialize this MAC with a key and no parameters.
|
void | init(Key key, AlgorithmParameterSpec params) - Initialize this MAC with a key and parameters.
|
void | reset() - Reset this instance.
|
void | update(byte input) - Update the computation with a single byte.
|
void | update(byte[] input) - Update the computation with a byte array.
|
void | update(byte[] input, int offset, int length) - Update the computation with a portion of a byte array.
|
void | update(ByteBuffer buffer) - Update this MAC with the remaining bytes in the given buffer
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
Mac
protected Mac(MacSpi macSpi,
Provider provider,
String algorithm)
Creates a new Mac instance.
macSpi
- The underlying MAC implementation.provider
- The provider of this implementation.algorithm
- The name of this MAC algorithm.
doFinal
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.
- The message authentication code.
doFinal
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.
input
- The bytes to add.
- The message authentication code.
doFinal
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.
output
- The destination for the result.outOffset
- The index in the output array to start.
getInstance
public static final Mac getInstance(String algorithm)
throws NoSuchAlgorithmException
Create an instance of the named algorithm from the first provider with an
appropriate implementation.
algorithm
- The name of the algorithm.
- An appropriate Mac instance, if the specified algorithm is
implemented by a provider.
getInstance
public static final Mac getInstance(String algorithm,
String provider)
throws NoSuchAlgorithmException,
NoSuchProviderException
Create an instance of the named algorithm from the named provider.
algorithm
- The name of the algorithm.provider
- The name of the provider.
- An appropriate Mac instance, if the specified algorithm is
implemented by the named provider.
getInstance
public static final Mac getInstance(String algorithm,
Provider provider)
throws NoSuchAlgorithmException
Create an instance of the named algorithm from a provider.
algorithm
- The name of the algorithm.provider
- The provider.
- An appropriate Mac instance, if the specified algorithm is
implemented by the provider.
getProvider
public final Provider getProvider()
Get the provider of the underlying implementation.
init
public final void init(Key key)
throws InvalidKeyException
Initialize this MAC with a key and no parameters.
key
- The key to initialize this instance with.
reset
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.
update
public final void update(byte[] input,
int offset,
int length)
throws IllegalStateException
Update the computation with a portion of a byte array.
input
- The next bytes.offset
- The index in input
to start.length
- The number of bytes to update.
update
public final void update(ByteBuffer buffer)
Update this MAC with the remaining bytes in the given buffer
buffer
- The input buffer.
Mac.java -- The message authentication code interface.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.