Python hashlib 模块,blake2b() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用hashlib.blake2b()

项目:manubot    作者:greenelab    | 项目源码 | 文件源码
def get_citation_id(standard_citation):
    """
    Get the citation_id for a standard_citation.
    """
    assert '@' not in standard_citation
    as_bytes = standard_citation.encode()
    blake_hash = hashlib.blake2b(as_bytes, digest_size=6)
    digest = blake_hash.digest()
    citation_id = base62.encodebytes(digest)
    return citation_id
项目:livre-python    作者:HE-Arc    | 项目源码 | 文件源码
def sign(cookie):
    """Signe le cookie."""
    h = blake2b(digest_size=AUTH_SIZE, key=SECRET_KEY)
    h.update(cookie.output().encode('utf-8'))
    cookie['signature'] = h.hexdigest()
项目:showroom    作者:wlerin    | 项目源码 | 文件源码
def blake2bsum(filename):
    b2bhash = hashlib.blake2b(digest_size=32)
    try:
        return hashsum(b2bhash, filename)
    except FileNotFoundError:
        return ""
项目:veggiecron-server    作者:jacobbridges    | 项目源码 | 文件源码
def generate_auth_token(self, user_id):
        """Generate an auth token for the user."""
        user = await self.db.execute('SELECT * FROM user WHERE id = ?;', user_id)
        if user:
            user = user[0]
            token_data = bytes((user[1] + ':' + ':' + str(now().timestamp())), 'utf8')
            token = hashlib.blake2b(digest_size=16, key=self.private_key)
            token.update(token_data)
            token = '{0}:{1}'.format(token.hexdigest(), user[1])
            token_base64 = base64.b64encode(bytes(token, 'utf8')).decode("utf-8")
            await self.db.execute('UPDATE user SET token=? WHERE id = ?;', token_base64, user_id)
            return token_base64
        else:
            raise HTTPError(401, 'Cannot locate user with id "{}"'.format(user_id))