php hash_hmac(SHA512)to python new HMAC()
PHP代码
function get_signature($data, $secret_key) {
$algo = "sha512";
$result = hash_hmac(
$algo,
$data,
$secret_key,
false
);
return $result;
}
Python代码(尝试)
def get_signature(data, secret_key):
signature = hmac.new(secret_key.encode(), data.encode(), hashlib.sha512).hexdigest()
print(signature)
return signature
Hashed值不同。 如何从Python代码中获得与PHP代码相同的值?
谢谢!
php code
function get_signature($data, $secret_key) {
$algo = "sha512";
$result = hash_hmac(
$algo,
$data,
$secret_key,
false
);
return $result;
}
python code (Tried)
def get_signature(data, secret_key):
signature = hmac.new(secret_key.encode(), data.encode(), hashlib.sha512).hexdigest()
print(signature)
return signature
the hashed value is not same.
how can I get same value as in php code from python code?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码正常工作。
问题是在另一个代码上。
the code is working properly.
the issue was on another code.