Generating a Message Authentication Code (MAC) Key : Mac « Security « Java Tutorial






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

public class Main {
  public static void main(String[] argv) throws Exception {

    KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5");
    SecretKey key = keyGen.generateKey();

    // Generate a key for the HMAC-SHA1 keyed-hashing algorithm
    keyGen = KeyGenerator.getInstance("HmacSHA1");
    key = keyGen.generateKey();
  }
}








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.