Как перенести python hashlib в node.js crypto - PullRequest
0 голосов
/ 17 июня 2020

Я портирую программу python на node.js, и мне нужно сгенерировать ha sh для аутентификации на сервере - однако я не могу получить тот же результат для auth_ha sh / authHa sh из моей node.js его реализации. Что-то мне не хватает в цепочке событий в исходном python?

Python:

import hashlib
import hmac

auth_hash = hashlib.sha256(
                        hmac.new(
                                api_key.encode(),
                                _auth.encode(),
                                hashlib.sha1
                                ).hexdigest().encode()
                        ).hexdigest()

Node.js

const crypto = require('crypto');
const utf8 = require(utf8');

const encodedAuth = utf8.encode(auth);
const hash = crypto.createHmac('sha1', utf8.encode(creds.api_key))
    .update(encodedAuth)
    .digest('hex');
const authHash = crypto.createHmac('sha256', utf8.encode(hash)).digest('hex');
...