以下python代碼的等價HMAC SHA512 ruby代碼密鑰是什麼?用於Python的等效HMAC SHA512 ruby代碼密鑰
的Python:
import hmac
import hashlib
response = hmac.new(PRIVATE_KEY, post_data, hashlib.sha512).hexdigest()
如下我添加在紅寶石的碼。但不產生相同的響應,在python
紅寶石:
require 'digest/hmac'
response = Digest::HMAC.hexdigest(post_data, PRIVATE_KEY ,Digest::SHA512)
url_request_object = urllib2.Request( 「%S /%S」 %(BASE_API_URL,url_suffix才能) post_data, 頭) 響應= urllib2.urlopen(url_request_object)
以下是爲我工作:
digest = OpenSSL::Digest.new('sha512')
sign = OpenSSL::HMAC.hexdigest(digest, PRIVATE_KEY, post_data)