首页 > 解决方案 > Kucoin Api KC-API-PASSPHRASE 无效

问题描述

我试图调用“/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' 的值也是时间戳的值,我用服务器检查过

标签: javaencryptionbase64hmackucoin

解决方案


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


推荐阅读