All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.bitrich.xchangestream.gateio.GateioStreamingAuthHelper Maven / Gradle / Ivy

The newest version!
package info.bitrich.xchangestream.gateio;

import java.nio.charset.StandardCharsets;
import javax.crypto.Mac;
import org.knowm.xchange.gateio.service.GateioV4Digest;
import org.knowm.xchange.utils.DigestUtils;

public class GateioStreamingAuthHelper {

  private final GateioV4Digest gateioV4Digest;

  public GateioStreamingAuthHelper(String apiSecret) {
    gateioV4Digest = GateioV4Digest.createInstance(apiSecret);
  }

  /** Generates signature based on payload */
  public String sign(String channel, String event, String timestamp) {
    Mac mac = gateioV4Digest.getMac();

    String payloadToSign = String.format("channel=%s&event=%s&time=%s", channel, event, timestamp);
    mac.update(payloadToSign.getBytes(StandardCharsets.UTF_8));

    return DigestUtils.bytesToHex(mac.doFinal());
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy