Generate MAC
To generate a MAC:
Get an instance of a Mac object. Pass the algorithm as an argument.
Obtain an instance of the key.
Initialize the Mac object.
Convert the plaintext to a byte array and invoke the doFinal method of the Mac object to create the MAC.
Code sample
The following code sample uses the HmacSHA1 algorithm to create a MAC of the string password.
Mac mac = Mac.getInstance("HmacSHA1", "IngrianProvider");
SecretKey key = NAEKey.getSecretKey("mackey");
mac.init(key);
byte[] mactext = mac.doFinal("password".getBytes());