public static byte[] hmac_sha1(byte[] keyBytes,byte[] text) throws NoSuchAlgorithmException, InvalidKeyException {
  Mac hmacSha1;
  try {
    hmacSha1=Mac.getInstance("HmacSHA1");
  }
 catch (  final NoSuchAlgorithmException nsae) {
    hmacSha1=Mac.getInstance("HMAC-SHA-1");
  }
  final SecretKeySpec macKey=new SecretKeySpec(keyBytes,"RAW");
  hmacSha1.init(macKey);
  return hmacSha1.doFinal(text);
}

public static byte [ ] hmac_sha1 ( byte [ ] keyBytes , byte [ ] text ) throws NoSuchAlgorithmException , InvalidKeyException { Mac hmacSha1 ; try { hmacSha1 = Mac . getInstance ( "HmacSHA1" ) ; } catch ( final NoSuchAlgorithmException nsae ) { hmacSha1 = Mac . getInstance ( "HMAC-SHA-1" ) ; } final SecretKeySpec macKey = new SecretKeySpec ( keyBytes , "RAW" ) ; hmacSha1 . init ( macKey ) ; return hmacSha1 . doFinal ( text ) ; }
this method uses the jce to provide the hmac - sha - 1 algorithm . hmac computes a hashed message authentication code and in this case sha1 is the hash algorithm used .
