Use MAC : Mac « Security « Java Tutorial






import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;

public class MainClass {
  public static void main(String[] args) throws Exception {
    String alg = "HmacMD5";
    Mac mac = Mac.getInstance(alg);
    KeyGenerator kg = KeyGenerator.getInstance(alg);
    SecretKey key = kg.generateKey();
    mac.init(key);
    mac.update("test".getBytes());
    byte[] b = mac.doFinal();
    System.out.println(new String(b));

  }
}








36.25.Mac
36.25.1.Mac creation
36.25.2.Use MAC
36.25.3.Generating a Message Authentication Code (MAC) Key
36.25.4.Generating a MAC from a text input using a random key.