public static String sign(String data, String key) throws InvalidKeyException {

    Mac sha256HMAC;
    try {
      sha256HMAC = Mac.getInstance(HMAC_SHA256);
    } catch (NoSuchAlgorithmException e) {
      return null;
    }

    SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(), HMAC_SHA256);
    sha256HMAC.init(secret_key);

    return Hex.encodeHexString(sha256HMAC.doFinal(data.getBytes()));
  }