A MAC provides a way to check the integrity of information transmitted over or stored in an unreliable medium, based on a secret key. Typically, message authentication codes are used between two parties that share a secret key in order to validate information transmitted between these parties.
A MAC mechanism that is based on cryptographic hash functions is referred to as HMAC. HMAC can be used with any cryptographic hash function, e.g., SHA256 or SHA384, in combination with a secret shared key. HMAC is specified in RFC 2104.
Every implementation of the Java platform is required to support
the following standard Mac algorithms:
HmacSHA1HmacSHA256PBEWithHmacSHA256| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private static final Debug | |
| private Provider. | |
| private boolean | |
| private final Object | |
| private static final Debug | |
| private Provider | |
| private Iterator | |
| private static final boolean | |
| private MacSpi | |
| private static int |
| Access | Constructor and Description |
|---|---|
| protected | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| private void | |
| public final Object | Returns: a clone if the provider implementation is cloneable.Overrides java. Returns a clone if the provider implementation is cloneable. |
| public final byte[] | |
| public final void | doFinal(byte[]
the buffer where the MAC result is stored output, int the offset in outOffset)output where the MAC is
storedFinishes the MAC operation. |
| public final byte[] | Returns: the MAC result.data in bytes input)Processes the given array of bytes and finishes the MAC operation. |
| public final String | Returns: the algorithm name of thisMac object.Returns the algorithm name of this |
| public static final Mac | Returns: the newMac objectthe standard name of the requested MAC algorithm.
See the Mac section in the
Java Security Standard Algorithm Names Specification
for information about standard algorithm names. algorithm)Returns a |
| public static final Mac | Returns: the newMac objectthe standard name of the requested MAC algorithm.
See the Mac section in the
Java Security Standard Algorithm Names Specification
for information about standard algorithm names. algorithm, String the name of the provider. provider)Returns a |
| public static final Mac | Returns: the newMac objectthe standard name of the requested MAC algorithm.
See the Mac section in the
Java Security Standard Algorithm Names Specification
for information about standard algorithm names. algorithm, Provider the provider. provider)Returns a |
| public final int | |
| public final Provider | |
| private String | |
| public final void | |
| public final void | init(Key
the key. key, AlgorithmParameterSpec the algorithm parameters. params)Initializes this |
| public final void | |
| public final void | |
| public final void | |
| public final void | update(byte[]
the input buffer. input, int the offset in offset, int input where the input starts.the number of bytes to process. len)Processes the first |
| public final void | update(ByteBuffer
the ByteBuffer input)Processes |
| algorithm | back to summary |
|---|---|
| private final String algorithm | |
| debug | back to summary |
|---|---|
| private static final Debug debug | |
| firstService | back to summary |
|---|---|
| private Provider. | |
| initialized | back to summary |
|---|---|
| private boolean initialized | |
| lock | back to summary |
|---|---|
| private final Object lock | |
| pdebug | back to summary |
|---|---|
| private static final Debug pdebug | |
| provider | back to summary |
|---|---|
| private Provider provider | |
| serviceIterator | back to summary |
|---|---|
| private Iterator<Provider. | |
| skipDebug | back to summary |
|---|---|
| private static final boolean skipDebug | |
| spi | back to summary |
|---|---|
| private MacSpi spi | |
| warnCount | back to summary |
|---|---|
| private static int warnCount | |
| Mac | back to summary |
|---|---|
| protected Mac(MacSpi macSpi, Provider provider, String algorithm) Creates a MAC object. | |
| Mac | back to summary |
|---|---|
| private Mac(Provider. | |
| chooseFirstProvider | back to summary |
|---|---|
| pack-priv void chooseFirstProvider() Choose the Spi from the first provider available. Used if delayed provider selection is not possible because init() is not the first method called. | |
| chooseProvider | back to summary |
|---|---|
| private void chooseProvider(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException | |
| clone | back to summary |
|---|---|
| public final Object clone() throws CloneNotSupportedException Overrides java. Returns a clone if the provider implementation is cloneable.
| |
| doFinal | back to summary |
|---|---|
| public final byte[] doFinal() throws IllegalStateException Finishes the MAC operation. A call to this method resets this
| |
| doFinal | back to summary |
|---|---|
| public final void doFinal(byte[] output, int outOffset) throws ShortBufferException, IllegalStateException Finishes the MAC operation. A call to this method resets this The MAC result is stored in
| |
| doFinal | back to summary |
|---|---|
| public final byte[] doFinal(byte[] input) throws IllegalStateException Processes the given array of bytes and finishes the MAC operation. A call to this method resets this
| |
| getAlgorithm | back to summary |
|---|---|
| public final String getAlgorithm() Returns the algorithm name of this This is the same name that was specified in one of the
| |
| getInstance | back to summary |
|---|---|
| public static final Mac getInstance(String algorithm) throws NoSuchAlgorithmException Returns a This method traverses the list of registered security providers,
starting with the most preferred provider.
A new Note that the list of registered providers may be retrieved via
the Implementation Note The JDK Reference Implementation additionally uses the
| |
| getInstance | back to summary |
|---|---|
| public static final Mac getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException Returns a A new Note that the list of registered providers may be retrieved via
the
| |
| getInstance | back to summary |
|---|---|
| public static final Mac getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException Returns a A new
| |
| getMacLength | back to summary |
|---|---|
| public final int getMacLength() Returns the length of the MAC in bytes.
| |
| getProvider | back to summary |
|---|---|
| public final Provider getProvider() Returns the provider of this
| |
| getProviderName | back to summary |
|---|---|
| private String getProviderName() | |
| init | back to summary |
|---|---|
| public final void init(Key key) throws InvalidKeyException Initializes this
| |
| init | back to summary |
|---|---|
| public final void init(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException Initializes this
| |
| reset | back to summary |
|---|---|
| public final void reset() Resets this A call to this method resets this | |
| update | back to summary |
|---|---|
| public final void update(byte input) throws IllegalStateException Processes the given byte.
| |
| update | back to summary |
|---|---|
| public final void update(byte[] input) throws IllegalStateException Processes the given array of bytes.
| |
| update | back to summary |
|---|---|
| public final void update(byte[] input, int offset, int len) throws IllegalStateException Processes the first
| |
| update | back to summary |
|---|---|
| public final void update(ByteBuffer input) Processes
| |