1

I am trying to use this API bitmarket

First I would like to call basic method info that's why in postman I added to headers to fields:

  • API-Key -> my api key
  • API-Hash -> my hash which is generated below) via HMAC SHA512 signature.

How I generate API-Hash? I have written in Java simple method which looks like:

  public String encodeDataViaHMAC(String msg, String keyString, String algo) {
        String digest = null;
        try {
            SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), algo);
            Mac mac = Mac.getInstance(algo);
            mac.init(key);

            byte[] bytes = mac.doFinal(msg.getBytes("ASCII"));

            StringBuffer hash = new StringBuffer();
            for (int i = 0; i < bytes.length; i++) {
                String hex = Integer.toHexString(0xFF & bytes[i]);
                if (hex.length() == 1) {
                    hash.append('0');
                }
                hash.append(hex);
            }
            digest = hash.toString();
        } catch (UnsupportedEncodingException e) {
        } catch (InvalidKeyException e) {
        } catch (NoSuchAlgorithmException e) {
        }
        return digest;
    }

and then I pass to it parameters:

  • map of request parameters:

Map<String, Object> m = new LinkedHashMap<>(); m.put("method", "info"); m.put("tonce", System.currentTimeMillis());

  • private key
  • method name which is HmacSHA512

and after that I still get it postman error:

{"error":502,"errorMsg":"Invalid message hash","time":1514023708}

Does anyone can help what am I doing wrong and can help me to fix it?

Jan Testowy
  • 649
  • 3
  • 13
  • 32
  • Possible duplicate of [Compute HMAC-SHA512 with secret key in java](https://stackoverflow.com/questions/39355241/compute-hmac-sha512-with-secret-key-in-java) – Joe Dec 23 '17 at 11:12
  • I tried this. Doesn’t work also.. – Jan Testowy Dec 23 '17 at 11:20
  • HMAC keys are usually not Strings. Make sure you interpret the key and the data correctly (hex, base64 or any other encoding has to be decoded first). – Robert Dec 23 '17 at 12:37

0 Answers0