A Message Authentication Code, or MAC, is akin to a keyed hash function, in that it produces a fixed-length identifier for variable-length data along with a key. The purpose of a MAC is to guarantee the integrity and authenticity of data, as it is computationally infeasible to fake a MAC without knowledge of the key.
The following diagram shows the important classes participating in this package:
Here is a simple example of how to use the HMAC algorithm, with a SHA-1 hash.
IMac mac = MacFactory.getInstance("HMAC-SHA-160"); HashMap attributes = new HashMap(); attributes.put(IMac.MAC_KEY_MATERIAL, key_bytes); attributes.put(IMac.TRUNCATED_SIZE, new Integer(12)); mac.init(attributes); mac.update(input, 0, input.length); byte[] result = mac.digest();