本文整理汇总了Python中Crypto.Hash.HMAC.HMAC.update方法的典型用法代码示例。如果您正苦于以下问题:Python HMAC.update方法的具体用法?Python HMAC.update怎么用?Python HMAC.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypto.Hash.HMAC.HMAC
的用法示例。
在下文中一共展示了HMAC.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _hmacedString
# 需要导入模块: from Crypto.Hash.HMAC import HMAC [as 别名]
# 或者: from Crypto.Hash.HMAC.HMAC import update [as 别名]
def _hmacedString(key, string):
"""
Return the SHA-1 HMAC hash of the given key and string.
"""
hash = HMAC(key, digestmod=sha)
hash.update(string)
return hash.digest()
示例2: ExtractEntropySeed
# 需要导入模块: from Crypto.Hash.HMAC import HMAC [as 别名]
# 或者: from Crypto.Hash.HMAC.HMAC import update [as 别名]
def ExtractEntropySeed(rounds, username, password, salt=None):
# Concentrates and then extracts the random entropy provided
# by the password into a seed value for the first hash stage.
# If if an explicit salt value is missing, use a hash of
# the username as if it were the salt.
if salt is None:
salt = SHA512.new(username).digest()
# Confirm the supplied salt meets the minimum length of 64
# octets required, is aligned to a 32 octet boundary and does not
# exceed 1,024 octets. Some implementations may not handle salt
# values longer than 1,024 octets properly.
elif len(salt) < 64:
raise ValueError("The salt, if supplied, must be at least " \
"64 octets in length.")
elif operator.mod(len(salt), 32) != 0:
warnings.warn("The salt, if longer than 64 octets, should " \
"be aligned to a 32 octet boundary.")
elif len(salt) > 1024:
warnings.warn("The salt should not exceed 1,024 octets.")
# For salt values which don't match the 128 octets required for
# an HMAC key value, the salt is hashed twice using a 3 octet
# counter value of 0 and 1, and the outputs are concatenated.
if len(salt) != 128:
key = \
SHA512.new(salt + struct.pack('>I', 0)[1:4]).digest() + \
SHA512.new(salt + struct.pack('>I', 1)[1:4]).digest()
# If the supplied salt is 128 octets use it directly as the key value.
else:
key = salt
# Initialize the HMAC instance using the key created above.
hmac = HMAC(key, None, SHA512)
# Repeat the plaintext password successively based on
# the number of instances specified by the rounds variable.
for unused in range(0, rounds):
hmac.update(password)
# Create the 64 octet seed value.
seed = hmac.digest()
return seed