本文整理汇总了Python中Crypto.Hash.HMAC属性的典型用法代码示例。如果您正苦于以下问题:Python Hash.HMAC属性的具体用法?Python Hash.HMAC怎么用?Python Hash.HMAC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Crypto.Hash
的用法示例。
在下文中一共展示了Hash.HMAC属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expand
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import HMAC [as 别名]
def expand( self ):
"""
Return the expanded output key material.
The output key material is calculated based on the given PRK, info and
L.
"""
tmp = ""
# Prevent the accidental re-use of output keying material.
if len(self.T) > 0:
raise base.PluggableTransportError("HKDF-SHA256 OKM must not "
"be re-used by application.")
while self.length > len(self.T):
tmp = Crypto.Hash.HMAC.new(self.prk, tmp + self.info +
chr(self.ctr),
Crypto.Hash.SHA256).digest()
self.T += tmp
self.ctr += 1
return self.T[:self.length]
示例2: HMAC_SHA256_128
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import HMAC [as 别名]
def HMAC_SHA256_128( key, msg ):
"""
Return the HMAC-SHA256-128 of the given `msg' authenticated by `key'.
"""
assert(len(key) >= const.SHARED_SECRET_LENGTH)
h = Crypto.Hash.HMAC.new(key, msg, Crypto.Hash.SHA256)
# Return HMAC truncated to 128 out of 256 bits.
return h.digest()[:16]
示例3: extract
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import HMAC [as 别名]
def extract( self, salt, ikm ):
return Crypto.Hash.HMAC.new(salt, ikm, Crypto.Hash.SHA256).digest()
示例4: test3_invalidHMAC
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import HMAC [as 别名]
def test3_invalidHMAC( self ):
# Make the HMAC invalid.
handshake = self.udh.createHandshake()
if handshake[-1] != 'a':
handshake = handshake[:-1] + 'a'
else:
handshake = handshake[:-1] + 'b'
buf = obfs_buf.Buffer(handshake)
self.failIf(self.udh.receivePublicKey(buf, lambda x: x) == True)