hmac — 用于消息身份验证的键哈希

源代码: Lib/hmac.py


This module implements the HMAC algorithm as described by RFC 2104 .

hmac. new ( key , msg=None , digestmod )

Return a new hmac object. key is a bytes or bytearray object giving the secret key. If msg is present, the method call update(msg) is made. digestmod is the digest name, digest constructor or module for the HMAC object to use. It may be any name suitable to hashlib.new() . Despite its argument position, it is required.

3.4 版改变: 参数 key can be a bytes or bytearray object. Parameter msg can be of any type supported by hashlib . Parameter digestmod can be the name of a hash algorithm.

3.8 版改变: The digestmod argument is now required. Pass it as a keyword argument to avoid awkwardness when you do not have an initial msg .