将Python代码更改为Node.js代码(base64 / hmac256编码)



首先,很抱歉我的英语很差,谢谢你点击这个问题。

我试图将我的python代码更改为Node.js代码。(关于base64/HMAC编码)

问题是我找不到足够的方法来改变下面的python代码到Node.js代码

passphrase = base64.b64encode(
hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest())

我只是想使用节点的加密模块,但是在第一个'sha256'参数之后只有一个参数选项,如下所示。

crypto.createHmac('sha256', api_secret);
// There is no argument position of 'api_passphrase'

如何用两个创建hmac参数像node.js上的python代码?

对于python,

signature = base64.b64encode(
hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest())

在node . js

signature = crypto.createHmac('sha256', api_secret).update(str_to_sign).digest('base64');

最新更新