package org.jivesoftware.smack.util;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class MAC {
   public static final String HMACSHA1 = "HmacSHA1";
   private static Mac HMAC_SHA1;

   public static synchronized byte[] hmacsha1(SecretKeySpec key, byte[] input) throws InvalidKeyException {
      HMAC_SHA1.init(key);
      return HMAC_SHA1.doFinal(input);
   }

   public static byte[] hmacsha1(byte[] keyBytes, byte[] input) throws InvalidKeyException {
      SecretKeySpec key = new SecretKeySpec(keyBytes, "HmacSHA1");
      return hmacsha1(key, input);
   }

   static {
      try {
         HMAC_SHA1 = Mac.getInstance("HmacSHA1");
      } catch (NoSuchAlgorithmException var1) {
         throw new IllegalStateException(var1);
      }
   }
}
