python类blake2b()的实例源码

citations.py 文件源码 项目:manubot 作者: greenelab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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
exemple_blake2.py 文件源码 项目:livre-python 作者: HE-Arc 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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()
media.py 文件源码 项目:showroom 作者: wlerin 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def blake2bsum(filename):
    b2bhash = hashlib.blake2b(digest_size=32)
    try:
        return hashsum(b2bhash, filename)
    except FileNotFoundError:
        return ""
server.py 文件源码 项目:veggiecron-server 作者: jacobbridges 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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))


问题


面经


文章

微信
公众号

扫码关注公众号