kraken java授权错误{“error”:[“EAPI:无效签名”]
源代码是 以下是要点: 1.)用于(API键)和(API符号)的URLCoder给出了相同的错误,无论有无 2.)同时使用了kraken java授权错误{“error”:[“EAPI:无效签名”],java,base64,authorization,kraken.js,gitkraken,Java,Base64,Authorization,Kraken.js,Gitkraken,源代码是 以下是要点: 1.)用于(API键)和(API符号)的URLCoder给出了相同的错误,无论有无 2.)同时使用了Base64.decodeBase64和Base64.getDecoder().decode,但仍然得到相同的错误 3.)使用concatarray(stringToBytes(路径)、sha256(nonce+postdate)获取相同错误 和path+sha256(nonce+postdata) 4.)能够正确检测API密钥 private static final S
Base64.decodeBase64
和Base64.getDecoder().decode
,但仍然得到相同的错误
3.)使用concatarray(stringToBytes(路径)、sha256(nonce+postdate)获取相同错误
和path+sha256(nonce+postdata)
4.)能够正确检测API密钥
private static final String REQUEST_API_SIGN = "musing";
private static final String REQUEST_API_KEY = "mike";
private static final String REQUEST_USER_AGENT = "User-Agent";
private static final String REQUEST_POST = "POST";
private static final String PUBLIC_URL = "https://api.kraken.com/0/public/";
private static final String PRIVATE_URL = "https://api.kraken.com/0/private/Balance";
main() {
HttpsURLConnection connection = null;
connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod(REQUEST_POST);
if (!isPublic) {
sign = Base64.getEncoder().encodeToString(createSignature(nonce, "/0/private/Balance", postData)); //path is "/version/private/method";
connection.addRequestProperty("API-Key", URLEncoder.encode(REQUEST_API_KEY, "UTF-8"));
connection.addRequestProperty("API-Sign", URLEncoder.encode(sign, "UTF-8"));
connection.setRequestProperty("Content-Length", String.valueOf(postData.length()));
connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8;application/x-www-form-urlencoded");
connection.setRequestProperty("Accept-Charset", "UTF-8");
// connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Accept", "application/x-www-form-urlencoded; charset=utf-8");
connection.setUseCaches(false);
connection.addRequestProperty(REQUEST_USER_AGENT, "Mozilla/4.0");
connection.setDoOutput(true);
connection.setDoInput(true);
try {
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(postData);
out.flush();
}
finally {
}
}
try {
BufferedReader in =new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
response.append(line);
}
return Response.status(200).entity(response.toString()).build();
}
}
public static byte[] concatArrays(byte[] a, byte[] b) {
if (a == null || b == null) {
throw new IllegalArgumentException(ERROR_NULL_ARRAYS);
}
byte[] concat = new byte[a.length + b.length];
for (int i = 0; i < concat.length; i++) {
concat[i] = i < a.length ? a[i] : b[i - a.length];
}
return concat;
}
private static byte[] createSignature(long nonce, String path, String postdata) throws NoSuchAlgorithmException, IOException, InvalidKeyException {
return hmac3(concatArrays(stringToBytes(path), sha256(nonce + post Data)), Base64.getDecoder().decode(REQUEST_API_SIGN));
}
public static byte[] stringToBytes(String input) {
if (input == null) {
throw new IllegalArgumentException(ERROR_NULL_INPUT);
}
return input.getBytes(Charset.forName(UTF8));
}
public static String sha256Hex(String text) throws NoSuchAlgorithmException, IOException {
return org.apache.commons.codec.digest.DigestUtils.sha256Hex(text);
}
public static byte[] sha256(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(text.getBytes("UTF-8"));
// md.update(text.getBytes());
byte[] digest = md.digest();
return digest;
}
public static byte[] hmacSha512(byte[] key, byte[] message) throws NoSuchAlgorithmException, InvalidKeyException {
Mac mac = Mac.getInstance(HMAC_SHA512);
mac.init(new SecretKeySpec(key, HMAC_SHA512));
return mac.doFinal(message);
}
public static byte[] hmac3(byte[] text, byte[] secret) {
Mac mac = null;
SecretKeySpec key = null;
// Create a new secret key
try {
key = new SecretKeySpec(secret, "HmacSHA512");
}
finally {
}
// Create a new mac
try {
mac = Mac.getInstance("HmacSHA512");
} catch(NoSuchAlgorithmException nsae) {
System.err.println("No such algorithm exception: " + nsae.toString());
return null;
}
// Init mac with key.
try {
mac.init(key);
} catch(InvalidKeyException ike) {
System.err.println("Invalid key exception: " + ike.toString());
return null;
}
// Encode the text with the secret
try {
//String s;
byte[] s = mac.doFinal(text);
return s;
}
finally {
}
}
private static final String REQUEST\u API\u SIGN=“musing”;
私有静态最终字符串请求\u API\u KEY=“mike”;
私有静态最终字符串请求\u USER\u AGENT=“USER AGENT”;
私有静态最终字符串请求\u POST=“POST”;
私有静态最终字符串PUBLIC_URL=”https://api.kraken.com/0/public/";
private静态最终字符串private_URL=”https://api.kraken.com/0/private/Balance";
main(){
HttpsURLConnection连接=null;
connection=(HttpsURLConnection)url.openConnection();
connection.setRequestMethod(请求发布);
如果(!isPublic){
sign=Base64.getEncoder().encodeToString(createSignature(nonce,“/0/private/Balance”,postData));//路径为“/version/private/method”;
connection.addRequestProperty(“API键”,URLEncoder.encode(请求API键,UTF-8”);
connection.addRequestProperty(“API符号”,URLEncoder.encode(符号,“UTF-8”);
connection.setRequestProperty(“Content-Length”,String.valueOf(postData.Length());
setRequestProperty(“内容类型”,“文本/普通;字符集=utf-8;应用程序/x-www-form-urlencoded”);
setRequestProperty(“接受字符集”、“UTF-8”);
//connection.setRequestProperty(“内容类型”、“应用程序/x-www-form-urlencoded”);
connection.setRequestProperty(“Accept”,“application/x-www-form-urlencoded;charset=utf-8”);
connection.setUseCaches(false);
addRequestProperty(请求用户代理,“Mozilla/4.0”);
connection.setDoOutput(真);
connection.setDoInput(true);
试一试{
OutputStreamWriter out=新的OutputStreamWriter(connection.getOutputStream());
out.write(postData);
out.flush();
}
最后{
}
}
试一试{
BufferedReader in=新的BufferedReader(新的InputStreamReader(connection.getInputStream());
StringBuilder响应=新建StringBuilder();
弦线;
而((line=in.readLine())!=null){
响应。追加(行);
}
返回Response.status(200).entity(Response.toString()).build();
}
}
公共静态字节[]concatarray(字节[]a,字节[]b){
如果(a==null | | b==null){
抛出新的IllegalArgumentException(错误\u空\u数组);
}
字节[]concat=新字节[a.length+b.length];
对于(int i=0;i
{“错误”:[“EAPI:无效签名”]}
您可以发布一个MCVE吗?请参阅以获取一个工作示例。