当前位置: 首页>>代码示例>>Python>>正文


Python HMAC.update方法代码示例

本文整理汇总了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()
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:9,代码来源:knownhosts.py

示例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
开发者ID:lavabit,项目名称:magma,代码行数:47,代码来源:stacie.py


注:本文中的Crypto.Hash.HMAC.HMAC.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。