package com.binance.connector.client.utils.signaturegenerator;

import com.binance.connector.client.utils.ParameterChecker;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;

/* loaded from: binance-connector-java-3.0.0rc3.jar:com/binance/connector/client/utils/signaturegenerator/HmacSignatureGenerator.class */
public final class HmacSignatureGenerator implements SignatureGenerator {
    private static final String HMAC_SHA256 = "HmacSHA256";
    private String apiSecret;

    public HmacSignatureGenerator(String apiSecret) {
        ParameterChecker.checkParameterType(apiSecret, String.class, "apiSecret");
        this.apiSecret = apiSecret;
    }

    @Override // com.binance.connector.client.utils.signaturegenerator.SignatureGenerator
    public String getSignature(String data) {
        try {
            SecretKeySpec secretKeySpec = new SecretKeySpec(this.apiSecret.getBytes(), HMAC_SHA256);
            Mac mac = Mac.getInstance(HMAC_SHA256);
            mac.init(secretKeySpec);
            return Hex.encodeHexString(mac.doFinal(data.getBytes()));
        } catch (Exception e) {
            throw new RuntimeException("Failed to calculate hmac-sha256", e);
        }
    }
}
