本文整理汇总了Python中hmac.HMAC.hexdigest方法的典型用法代码示例。如果您正苦于以下问题:Python HMAC.hexdigest方法的具体用法?Python HMAC.hexdigest怎么用?Python HMAC.hexdigest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmac.HMAC
的用法示例。
在下文中一共展示了HMAC.hexdigest方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: shatest
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def shatest(key, data, digest):
h = HMAC(key, data, digestmod=_hashlib.sha1)
assertEqual(h.hexdigest().upper(), digest.upper())
assertEqual(h.name, "hmac-sha1")
assertEqual(h.digest_size, 20)
assertEqual(h.block_size, 64)
h = HMAC(key, data, digestmod='sha1')
assertEqual(h.hexdigest().upper(), digest.upper())
assertEqual(h.name, "hmac-sha1")
assertEqual(h.digest_size, 20)
assertEqual(h.block_size, 64)
示例2: hmactest
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def hmactest(key, data, hexdigests):
hmac_name = "hmac-" + hash_name
h = HMAC(key, data, digestmod=hashfunc)
assertEqual(h.hexdigest().lower(), hexdigests[hashfunc])
assertEqual(h.name, hmac_name)
assertEqual(h.digest_size, digest_size)
assertEqual(h.block_size, block_size)
h = HMAC(key, data, digestmod=hash_name)
assertEqual(h.hexdigest().lower(), hexdigests[hashfunc])
assertEqual(h.name, hmac_name)
assertEqual(h.digest_size, digest_size)
assertEqual(h.block_size, block_size)
示例3: test_hmac_package
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def test_hmac_package(self):
from hmac import HMAC
import hashlib
k_hex = binascii.hexlify("")
hmac = HMAC(k_hex, digestmod=hashlib.sha1)
self.assertEquals(hmac.hexdigest(), self.result['empty'])
k_hex = binascii.hexlify("key")
d_hex = binascii.hexlify("The quick brown fox jumps over the lazy dog")
hmac1 = HMAC(k_hex, digestmod=hashlib.sha1)
hmac1.update(d_hex)
self.assertEquals(hmac.hexdigest(), self.result['empty'])
示例4: generate_signature
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def generate_signature(self):
from hmac import HMAC
from hashlib import sha256
key = self.webhook.secret.encode("utf-8")
msg = self.payload.encode("utf-8")
mac = HMAC(key, msg, digestmod=sha256)
return "sha256=" + mac.hexdigest()
示例5: _make_request
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def _make_request(self, data):
bsecret = self._secret.encode('ascii')
sign = HMAC(bsecret, digestmod=sha512)
sign.update(data.encode('ascii'))
header = {
'Content-type': self.content_type,
'Key': self._key,
'Sign': sign.hexdigest()
}
return Request(self.base, data, header)
示例6: make_signature
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def make_signature(endpoint, force_ts=None):
#
# Pick a timestamp and perform the signature required.
#
assert endpoint[0] == '/' and 'api.coinkite.com' not in endpoint, \
"Expecting abs url, got: %s" % endpoint
ts = force_ts or datetime.datetime.utcnow().isoformat()
data = endpoint + "|" + ts
hm = HMAC(API_SECRET, msg=data, digestmod=sha256)
return hm.hexdigest(), ts
示例7: compute_signature
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def compute_signature(self, nb):
"""Compute a notebook's signature
by hashing the entire contents of the notebook via HMAC digest.
"""
hmac = HMAC(self.secret, digestmod=self.digestmod)
# don't include the previous hash in the content to hash
with signature_removed(nb):
# sign the whole thing
for b in yield_everything(nb):
hmac.update(b)
return hmac.hexdigest()
示例8: send_status
# 需要导入模块: from hmac import HMAC [as 别名]
# 或者: from hmac.HMAC import hexdigest [as 别名]
def send_status(session,msg_type='doorspush'):
if not msg_type in ['doorspush','doorsbeat']:
raise ValueError('msg_type must be "doorspush" or "doorsbeat" not "{}"'.format(msg_type))
stat=get_status(session)
is_open=None
if stat.req_type=='open':
is_open=True
if stat.req_type=='close':
is_open=False
changed_on=stat.date.isoformat()
payload={'type':msg_type,'open':is_open,'changed_on':changed_on}
data=json.dumps({'client_id':config.fablab_client_id,'created_on':datetime.now(utc).isoformat(),'payload':payload}).encode('UTF-8')
hmac=HMAC(msg=data,key=config.fablab_client_key.encode('UTF-8'))
postdata=json.dumps({'hmac':hmac.hexdigest(),'data':data.decode('UTF-8')})
try:
req=urlopen(config.api_addr,data=postdata.encode('UTF-8'))
except HTTPError as e:
return (e)
return req