hotp.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:authenticator 作者: JeNeSuisPasDave 项目源码 文件源码
def generate_hmac(self, secret_key, counter):
        """Create a 160-bit HMAC from secret and counter.

        Args:
            secret_key: a byte string (recommended minimum 20 bytes) that is
                the shared secret between the client and server.
            counter: an integer value represented in an 8-byte string with
                the most significant byte first and least significant byte
                last

        Returns:
            The HMAC digest; a byte string, 20 bytes long.

        Raises:
            TypeError: if the counter and secret are not byte strings.
            ValueError: if the counter is not 8 bytes long.

        """
        from hashlib import sha1
        import hmac

        if not isinstance(secret_key, bytes):
            raise TypeError('secret_key must be a byte string')
        if not isinstance(counter, bytes):
            raise TypeError('counter must be a byte string')
        if (8 != len(counter)):
            raise ValueError('counter must be 8 bytes')

        hmac = hmac.new(secret_key, counter, sha1)
        hash = hmac.digest()
        return hash
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号