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






Generating a Message Authentication Code (MAC) Key

 

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();
  }
}

   
  








Related examples in the same category

1.Generating a Message Authentication Code (MAC)