我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用hashlib.blake2b()。
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
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()
def blake2bsum(filename): b2bhash = hashlib.blake2b(digest_size=32) try: return hashsum(b2bhash, filename) except FileNotFoundError: return ""
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))