如何基于NodeJS文档在Java中签署Coinbase消息?

时间:2019-06-29 07:35:09

标签: java coinbase-api

我在将Coinbase订单的消息签名到API时遇到问题。

在Coinbase(https://docs.pro.coinbase.com/#signing-a-message)的官方文档中,您可以阅读如何签名。

我在这里找到了一个非官方的Java代码; https://github.com/irufus/gdax-java/blob/master/src/main/java/com/coinbase/exchange/api/constants/GdaxConstants.java。基于此,我得出了以下代码:

        String prehash = timestamp + method.toUpperCase() + requestPath + body;
        byte[] secretDecoded = Base64.getDecoder().decode(secretKey);
         Mac SHARED_MAC = Mac.getInstance("HmacSHA256");
        SecretKeySpec keyspec = new SecretKeySpec(secretDecoded, SHARED_MAC.getAlgorithm());
        Mac sha256 = (Mac) SHARED_MAC.clone();
        sha256.init(keyspec);
        return Base64.getEncoder().encodeToString(sha256.doFinal(prehash.getBytes()));

当我发布上述结果时,我从api返回了“无效签名”响应。这是怎么了? ?

0 个答案:

没有答案
相关问题