编码 HMAC256 - Java 到 Python
Encoding HMAC256 - Java to Python
我需要将下面的 Java 代码转换为 Python,但似乎 运行 遇到检索所需输出的问题。我希望看看是否有人能指出我的错误
Java代码:
const crypto = require('crypto')
const qs = require('query-string')
const accessKey = '0a16ca22a837af8acae3b70f1952f311'
const accessSecret = 'fe266ab860ef6734192a9e90ad39405b'
const method = 'GET'
const timestamp = 1629339206369
const path = '/api/v2/loan/config'
const signStr = `method=${method}&path=${path}×tamp=${timestamp}`
// "method=GET&path=/api/v2/loan/config×tamp=1629339206369"
const sign = crypto.createHmac('sha256', accessSecret).update(signStr).digest('hex');
Java 输出:
8dafe94777e9130869ceedf9f123c5f6552efcff3cb139591834eb8a82cc7504
Python代码:
signStr = "method=GET&path=/api/v2/loan/config×tamp=1629339206369"
accessSecret = 'fe266ab860ef6734192a9e90ad39405b'
resp = hmac.new(accessSecret.encode('utf-8'), signStr.encode('utf-8'),
hashlib.sha256).hexdigest()
Python 输出:
f751679a9640cdea16a2cb625a2e797c7190cfd6901e729dcd6ca66519907ac6
谢谢
我刚刚 运行 你在 node.js 上的代码,得到的答案与 Python 完全相同。
> const method = 'GET'
> const timestamp = 1629339206369
> const path = '/api/v2/loan/config'
> const signStr = `method=${method}&path=${path}×tamp=${timestamp}`
> signStr
'method=GET&path=/api/v2/loan/config×tamp=1629339206369'
> const sign = crypto.createHmac('sha256', accessSecret).update(signStr).digest('hex');
> sign
'f751679a9640cdea16a2cb625a2e797c7190cfd6901e729dcd6ca66519907ac6'
我需要将下面的 Java 代码转换为 Python,但似乎 运行 遇到检索所需输出的问题。我希望看看是否有人能指出我的错误
Java代码:
const crypto = require('crypto')
const qs = require('query-string')
const accessKey = '0a16ca22a837af8acae3b70f1952f311'
const accessSecret = 'fe266ab860ef6734192a9e90ad39405b'
const method = 'GET'
const timestamp = 1629339206369
const path = '/api/v2/loan/config'
const signStr = `method=${method}&path=${path}×tamp=${timestamp}`
// "method=GET&path=/api/v2/loan/config×tamp=1629339206369"
const sign = crypto.createHmac('sha256', accessSecret).update(signStr).digest('hex');
Java 输出:
8dafe94777e9130869ceedf9f123c5f6552efcff3cb139591834eb8a82cc7504
Python代码:
signStr = "method=GET&path=/api/v2/loan/config×tamp=1629339206369"
accessSecret = 'fe266ab860ef6734192a9e90ad39405b'
resp = hmac.new(accessSecret.encode('utf-8'), signStr.encode('utf-8'),
hashlib.sha256).hexdigest()
Python 输出:
f751679a9640cdea16a2cb625a2e797c7190cfd6901e729dcd6ca66519907ac6
谢谢
我刚刚 运行 你在 node.js 上的代码,得到的答案与 Python 完全相同。
> const method = 'GET'
> const timestamp = 1629339206369
> const path = '/api/v2/loan/config'
> const signStr = `method=${method}&path=${path}×tamp=${timestamp}`
> signStr
'method=GET&path=/api/v2/loan/config×tamp=1629339206369'
> const sign = crypto.createHmac('sha256', accessSecret).update(signStr).digest('hex');
> sign
'f751679a9640cdea16a2cb625a2e797c7190cfd6901e729dcd6ca66519907ac6'