Axios加密的POST参数

问题描述 投票:0回答:1

我想使用bitgrail的API(docs:https://bitgrail.com/api-documentation)。并要求余额。要做到这一点,你必须使用HMAC-SHA512和你的API-Secret设置一个SIGNATURE,其中包括加密的post参数。

所以你必须发送这些数据:

标题:

KEY - 公共API密钥

SIGNATURE - 使用您的秘密API密钥使用HMAC-SHA512算法加密POST参数

数据:

nonce - 整数,始终大于先前调用的nonce。

但每当我尝试发送请求时,我都会收到“身份验证失败” - 来自Bitgrail的错误。

参数设置如下:

params = {}
params.nonce = n();

然后像这样加密:

 let hmac = crypto.createHmac('sha512', 'MYSECRET');
 let digest = hmac.update(params.toString()).digest('hex');
 let signature = new Buffer(digest).toString('base64');

也许'params.toString()'不起作用。我是否必须将params变量设置为数组?

rest post header axios signing
1个回答
0
投票

我自己想通过使用const { URLSearchParams } = require('url');并删除这一行:let signature = new Buffer(digest).toString('base64');并仅使用摘要作为签名。

© www.soinside.com 2019 - 2024. All rights reserved.