【问题标题】:Kucoin Api KC-API-PASSPHRASE is InvalidKucoin Api KC-API-PASSPHRASE 无效
【发布时间】:2021-10-17 19:38:58
【问题描述】:

我试图调用“/api/v1/sub-accounts”端点来获取账户余额,但它有问题! 这是我的代码:

public Observable<Response<String>> getBalance(){
    long timestamp = Timestamp.from(Instant.now()).getTime() + localDelayTime;
    return service.getBalance(
            apiKey+"",
                    timestamp+"",
                    base64(encode(secKey,(timestamp+"GET"+"/api/v1/sub-accounts"+"")))+"",
            base64(encode(secKey,passPhrase))+"",

            "2")
            .subscribeOn(Schedulers.io())
            .unsubscribeOn(Schedulers.io())
            .retry(2)
            .timeout(10,TimeUnit.SECONDS);
}

我的加密方法是:

private String base64(String encode) {
    try {
        return Base64.getEncoder().encodeToString((encode).getBytes(StandardCharsets.UTF_8));
    }catch (NullPointerException e){
        return "";
    }
}

public static String encode(String key, String data) {
    Mac sha256;
    try {
        sha256 = Mac.getInstance("HmacSHA256");
        SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
        sha256.init(secret_key);
        return bytesToHex(sha256.doFinal(data.getBytes("UTF-8")));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

public static String bytesToHex(byte[] bytes) {
    char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
    char[] hexChars = new char[bytes.length * 2];
    for (int j = 0; j < bytes.length; j++) {
        int v = bytes[j] & 0xFF;
        hexChars[j * 2] = HEX_ARRAY[v >>> 4];
        hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
    }
    return new String(hexChars);
}

'apikey , secretKey , passPhrase' 的值是对的 还有时间戳的值,我用服务器检查过

【问题讨论】:

    标签: java encryption base64 hmac kucoin


    【解决方案1】:

    这也让我措手不及。 密码是您帐户的密码,而不是您使用的交易 6 位数代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-21
      • 2022-08-20
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      相关资源
      最近更新 更多