@Override public String digestParams(RestInvocation restInvocation) { String httpMethod = restInvocation.getHttpMethod(); String host = getHost(restInvocation.getBaseUrl()); String method = "/" + restInvocation.getMethodPath(); String query = Stream.of( restInvocation.getParamsMap().get(FormParam.class), restInvocation.getParamsMap().get(QueryParam.class)) .map(Params::asHttpHeaders) .map(Map::entrySet) .flatMap(Collection::stream) .filter(e -> !"Signature".equals(e.getKey())) .sorted(Map.Entry.comparingByKey()) .map(e -> e.getKey() + "=" + encodeValue(e.getValue())) .collect(Collectors.joining("&")); String toSign = String.format("%s\n%s\n%s\n%s", httpMethod, host, method, query); Mac mac = getMac(); String signature = encodeValue(Base64.getEncoder().encodeToString(mac.doFinal(toSign.getBytes())).trim()); replaceSignatureUrl(restInvocation, signature); return signature; }
@Override public String digestParams(RestInvocation restInvocation) { String pathWithQueryString = restInvocation.getInvocationUrl().replace(restInvocation.getBaseUrl(), ""); String message = restInvocation.getParamValue(HeaderParam.class, "CB-ACCESS-TIMESTAMP").toString() + restInvocation.getHttpMethod() + pathWithQueryString + (restInvocation.getRequestBody() != null ? restInvocation.getRequestBody() : ""); Mac mac256 = getMac(); try { mac256.update(message.getBytes("UTF-8")); } catch (Exception e) { throw new ExchangeException("Digest encoding exception", e); } signature = Base64.getEncoder().encodeToString(mac256.doFinal()); return signature; }
@Override public String digestParams(RestInvocation restInvocation) { String nonce = restInvocation.getParamValue(HeaderParam.class, "api-expires").toString(); String path = restInvocation.getInvocationUrl().split(restInvocation.getBaseUrl())[1]; String payload = restInvocation.getHttpMethod() + "/" + path + nonce + restInvocation.getRequestBody(); return digestString(payload); }
@Override public String digestParams(RestInvocation restInvocation) { String nonce = restInvocation.getParamValue(HeaderParam.class, "api-expires").toString(); String path = restInvocation.getInvocationUrl().split(restInvocation.getBaseUrl())[1]; String payload = restInvocation.getHttpMethod() + "/" + path + nonce + restInvocation.getRequestBody(); return digestString(payload); }
@Override public String digestParams(RestInvocation restInvocation) { String pathWithQueryString = restInvocation.getInvocationUrl().replace(restInvocation.getBaseUrl(), ""); String message = restInvocation.getParamValue(HeaderParam.class, "CB-ACCESS-TIMESTAMP").toString() + restInvocation.getHttpMethod() + pathWithQueryString + (restInvocation.getRequestBody() != null ? restInvocation.getRequestBody() : ""); Mac mac256 = getMac(); try { mac256.update(message.getBytes("UTF-8")); } catch (Exception e) { throw new ExchangeException("Digest encoding exception", e); } signature = Base64.getEncoder().encodeToString(mac256.doFinal()); return signature; }