本文整理匯總了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)