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

estonlabs.cxtl.exchanges.binance.lib.BinanceAuthenticator Maven / Gradle / Ivy

There is a newer version: 1.4.14
Show newest version
package estonlabs.cxtl.exchanges.binance.lib;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import static estonlabs.cxtl.common.util.HexUtil.bytesToHex;

public class BinanceAuthenticator {
    private static final String HMAC_SHA256 = "HmacSHA256";


    public static String getSignature(String data, String key) {
        byte[] hmacSha256;
        try {
            SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), HMAC_SHA256);
            Mac mac = Mac.getInstance(HMAC_SHA256);
            mac.init(secretKeySpec);
            hmacSha256 = mac.doFinal(data.getBytes());
        } catch (Exception e) {
            throw new RuntimeException("Failed to calculate hmac-sha256", e);
        }
        return bytesToHex(hmacSha256);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy