Generating an HMAC-MD5 hash using Java

The following Java code generates an HMAC-MD5 hash of a query string and appends the value to end of a completion notification URL (pixel):

String sharedKey = "[YOUR SHARED KEY]"; // your shared key

SecretKeySpec secretKeySpec =
  new SecretKeySpec(sharedKey.getBytes("UTF-8"), "hmacMD5");
Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm());

String query = "tp_aid=xxxxxx&tp_sid=Uyyyyyy&tp_t=62135162532"; // the query string to sign

byte[] hashBytes = mac.doFinal(query.getBytes("UTF-8"));
String actualHash = Hex.encodeHexString(hashBytes);
String pixelUrl = "" + query + "&tp_v1=" + actualHash;