@Override public String digestParams(RestInvocation restInvocation) { String ApiKey = restInvocation.getHttpHeadersFromParams().get("X-PCK"); String timestamp = restInvocation.getHttpHeadersFromParams().get("X-Stamp"); return generateHash(ApiKey, timestamp); }
@Override public String digestParams(RestInvocation restInvocation) { // The Bitcointoyou API specifies that signature field is a concat between nonce and API Key. String signature = restInvocation.getHttpHeadersFromParams().get("nonce") + apiKey; return Base64.getEncoder().encodeToString(getMac().doFinal(signature.getBytes())).toUpperCase(); } }
@Override public String digestParams(RestInvocation restInvocation) { try { Map<String, String> headers = restInvocation.getHttpHeadersFromParams(); String apiKey = headers.get("API-Key"); Long requestTimestamp = Long.parseLong(headers.get("Request-Timestamp")); String hashContent = apiKey + requestTimestamp; Mac mac = getMac(); mac.update(hashContent.getBytes("UTF-8")); return String.format("%0128x", new BigInteger(1, mac.doFinal())); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Illegal encoding, check the code.", e); } } }
@Override public String digestParams(RestInvocation restInvocation) { final String path = restInvocation.getPath(); final Map<String, String> httpHeadersFromParams = restInvocation.getHttpHeadersFromParams(); final String requestBody = restInvocation.getRequestBody(); final String input = String.join(";", path, requestBody, httpHeadersFromParams.get("Api-Nonce")); final Mac mac = getMac(); try { mac.update(input.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } final String printBase64Binary = bytesToHex(mac.doFinal()); return Base64.getEncoder().encodeToString(printBase64Binary.getBytes()); } }
@Override public String digestParams(RestInvocation restInvocation) { String timestamp = restInvocation.getHttpHeadersFromParams().get("AC-ACCESS-TIMESTAMP"); String method = restInvocation.getHttpMethod(); String path = restInvocation.getPath(); String queryParameters = restInvocation.getQueryString(); if (!queryParameters.isEmpty()) { queryParameters = '?' + queryParameters; } String body = restInvocation.getRequestBody(); body = body == null ? "" : body; String queryArgs = timestamp + method + path + (queryParameters + body); Mac shaMac = getMac(); final byte[] macData = shaMac.doFinal(queryArgs.getBytes()); return Base64.getEncoder().encodeToString(macData); } }
Map<String, String> httpHeaders = restInvocation.getHttpHeadersFromParams(); String currentNonce = httpHeaders.get("X-Auth-Nonce"); String currentTimestamp = httpHeaders.get("X-Auth-Timestamp");
@Override public String digestParams(RestInvocation restInvocation) { // Step 1: concatenate URL with query string String completeURL = restInvocation.getInvocationUrl(); // Step 2: create md5-Hash of the POST-Parameters for the HMAC-data String httpMethod = restInvocation.getHttpMethod(); String requestBody = restInvocation.getRequestBody(); String md5; if ("POST".equals(httpMethod)) { md5 = getMD5(requestBody); } else { md5 = "d41d8cd98f00b204e9800998ecf8427e"; // no post params for GET methods } // Step 3: concat HMAC-input // http_method+'#'+uri+'#'+api_key+'#'+nonce+'#'+post_parameter_md5_hashed_url_encoded_query_string String nonce = restInvocation.getHttpHeadersFromParams().get("X-API-NONCE"); String hmac_data = String.format("%s#%s#%s#%s#%s", httpMethod, completeURL, apiKey, nonce, md5); // Step 3: Create actual sha256-HMAC Mac mac256 = getMac(); mac256.update(hmac_data.getBytes()); return String.format("%064x", new BigInteger(1, mac256.doFinal())); }
@Override public String digestParams(RestInvocation restInvocation) { String date = restInvocation.getHttpHeadersFromParams().get("date"); String sha1 = sha1(restInvocation.getRequestBody()); String s = restInvocation.getHttpMethod() + "\n" + sha1 + "\n" + MediaType.APPLICATION_JSON + "\n" + date + "\n" + "/" + restInvocation.getPath(); Mac mac = getMac(); mac.update(s.getBytes()); return api + ":" + Base64.getEncoder().encodeToString(mac.doFinal()); }
@Override public String digestParams(RestInvocation restInvocation) { String queryString = restInvocation.getQueryString(); // System.out.println("queryString = " + queryString); String httpMethod = restInvocation.getHttpMethod(); String uri = restInvocation.getPath(); if (queryString != null && queryString.length() > 0) { uri += "?" + restInvocation.getQueryString(); } // System.out.println("uri = " + uri); String requestBody = restInvocation.getRequestBody(); String nonce = restInvocation.getHttpHeadersFromParams().get(Bitflyer.ACCESS_TIMESTAMP); // ACCESS-SIGN is the resulting HMAC-SHA256 signature done with the API secret path using the // ACCESS-TIMESTAMP, HTTP method, request path, and // request body linked together as a character string. String hmac_data = String.format("%s%s%s%s", nonce, httpMethod, uri, requestBody); Mac mac256 = getMac(); mac256.update(hmac_data.getBytes()); return DigestUtils.bytesToHex(mac256.doFinal()).trim(); } }
@Override public String digestParams(RestInvocation restInvocation) { String tonce = restInvocation.getHttpHeadersFromParams().get("Json-Rpc-Tonce");
Map<String, String> httpHeaders = restInvocation.getHttpHeadersFromParams(); String currentNonce = httpHeaders.get("X-Auth-Nonce"); String currentTimestamp = httpHeaders.get("X-Auth-Timestamp");
/** * @deprecated this method will be made package local very soon. * Use {@link #getHttpHeadersFromParams()} instead. * @return */ @Deprecated public Map<String, String> getAllHttpHeaders() { if (allHttpHeaders == null) { allHttpHeaders = new HashMap<>(); allHttpHeaders.putAll(getHttpHeadersFromParams()); if (methodMetadata.getReqContentType() != null) { allHttpHeaders.put("Content-Type", methodMetadata.getReqContentType()); } if (methodMetadata.getResContentType() != null) { allHttpHeaders.put("Accept", methodMetadata.getResContentType()); } } return allHttpHeaders; }
/** * @deprecated this method will be made package local very soon. * Use {@link #getHttpHeadersFromParams()} instead. * @return */ @Deprecated public Map<String, String> getAllHttpHeaders() { if (allHttpHeaders == null) { allHttpHeaders = new HashMap<>(); allHttpHeaders.putAll(getHttpHeadersFromParams()); if (methodMetadata.getReqContentType() != null) { allHttpHeaders.put("Content-Type", methodMetadata.getReqContentType()); } if (methodMetadata.getResContentType() != null) { allHttpHeaders.put("Accept", methodMetadata.getResContentType()); } } return allHttpHeaders; }
@Override public String digestParams(RestInvocation restInvocation) { String queryString = restInvocation.getQueryString(); // System.out.println("queryString = " + queryString); String httpMethod = restInvocation.getHttpMethod(); String uri = restInvocation.getPath(); if (queryString != null && queryString.length() > 0) { uri += "?" + restInvocation.getQueryString(); } // System.out.println("uri = " + uri); String requestBody = restInvocation.getRequestBody(); String nonce = restInvocation.getHttpHeadersFromParams().get(Bitflyer.ACCESS_TIMESTAMP); // ACCESS-SIGN is the resulting HMAC-SHA256 signature done with the API secret path using the // ACCESS-TIMESTAMP, HTTP method, request path, and // request body linked together as a character string. String hmac_data = String.format("%s%s%s%s", nonce, httpMethod, uri, requestBody); Mac mac256 = getMac(); mac256.update(hmac_data.getBytes()); return DigestUtils.bytesToHex(mac256.doFinal()).trim(); } }
@Override public String digestParams(RestInvocation restInvocation) { String tonce = restInvocation.getHttpHeadersFromParams().get("Json-Rpc-Tonce"); LakeBTCRequest request = null; for (Object param : restInvocation.getUnannanotatedParams()) { if (param instanceof LakeBTCRequest) { request = (LakeBTCRequest) param; } } if (request == null) { throw new IllegalArgumentException("No LakeBTCDigest found."); } final long id = request.getId(); final String method = request.getRequestMethod(); final String params = ""; //stripParams(request.getParams()); String signature = String.format("tonce=%s&accesskey=%s&requestmethod=%s&id=%d&method=%s¶ms=%s", tonce, clientId, method, id, request.getMethod(), params); log.debug("signature message: {}", signature); Mac mac = getMac(); byte[] hash = mac.doFinal(signature.getBytes()); BasicAuthCredentials auth = new BasicAuthCredentials(apiKey, LakeBTCUtil.bytesToHex(hash)); return auth.digestParams(restInvocation); }
@Override public String digestParams(RestInvocation restInvocation) { String tonce = restInvocation.getHttpHeadersFromParams().get("Json-Rpc-Tonce"); BTCChinaRequest request = null; for (Object param : restInvocation.getUnannanotatedParams()) { if (param instanceof BTCChinaRequest) { request = (BTCChinaRequest) param; } } if (request == null) { throw new IllegalArgumentException("No BTCChinaRequest found."); } final long id = request.getId(); final String method = request.getMethod(); final String params = stripParams(request.getParams()); String signature = String.format("tonce=%s&accesskey=%s&requestmethod=%s&id=%d&method=%s¶ms=%s", tonce, exchangeAccessKey, "post", id, method, params); log.debug("signature message: {}", signature); Mac mac = getMac(); byte[] hash = mac.doFinal(signature.getBytes()); BasicAuthCredentials auth = new BasicAuthCredentials(exchangeAccessKey, BTCChinaUtils.bytesToHex(hash)); return auth.digestParams(restInvocation); }