Name

Mac

Synopsis

This class defines an API for computing a message authentication code (MAC) that can check the integrity of information transmitted between two parties that share a secret key. A MAC is similar to a digital signature, except that it is generated with a secret key rather than with a public/private key pair. The Mac class is algorithm-independent and provider-based. Obtain a Mac object by calling one of the static getInstance( ) factory methods and specifying the name of the desired MAC algorithm and, optionally, the name of the provider of the desired implementation. In Java 5.0 The “SunJCE” provider implement MAC algorithms with the following names:

HmacMD5

HmacSHA1

HmacSHA256

HmacSHA384

HmacSHA512

HmacPBESHA1

After obtaining a Mac object, initialize it by calling the init( ) method and specifying a SecretKey and, optionally, a java.security.spec.AlgorithmParameterSpec object. The “HmacMD5” and “HmacSHA1” algorithms can use any kind of SecretKey; they are not restricted to a particular cryptographic algorithm. And neither algorithm requires an AlgorithmParameterSpec object.

After obtaining and initializing a Mac object, specify the data for which the MAC is to be computed. If the data is contained in a single byte array, simply pass it to doFinal( ). If the data is streaming or is stored in various locations, you can supply the data in multiple calls to update( ). In Java 5.0, you can pass a ByteBuffer to update( ) which facilities use with the java.nio ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.