Verify MAC
To verify a MAC:
Obtain a [previously calculated MAC value]. Put that value in a byte array.
Get an instance of a Mac object. Pass the algorithm as an argument.
Obtain an instance of the key that was used to create the MAC.
Initialize the Mac object and pass the previously calculated MAC value by encapsulating the byte array in a
MACValue
object.Convert the original plaintext to a byte array and invoke the doFinal method of the Mac object to verify the previously calculated MAC.
Code sample
The following code sample compares the value of prevMac with a newly calculated MAC of the string password.
byte[] prevMac = ... /* get previously calculated MAC */
Mac mac = Mac.getInstance("HmacSHA1Verify", "IngrianProvider");
SecretKey key = NAEKey.getSecretKey("mackey");
mac.init(key, new MACValue(prevMac));
byte[] result = mac.doFinal("password".getBytes());
boolean verified = (result[0] == 1);
Note
Verifying a MAC is supported in both local and remote modes and is not supported with bulk operation.