首页 > 其他分享 >Strings must be encoded before hashing

Strings must be encoded before hashing

时间:2022-12-08 21:56:53浏览次数:45  
标签:format token encoded before Strings md5 hashing

Strings must be encoded before hashing

当我们将字符串传递给 hash 算法时,会出现 “TypeError: Strings must be encoded before hashing”。

解决错误,使用encode()

import hashlib, time


def get_token(username, token_id):
timestamp = int(time.time())
md5_format_str = "%s\n%s\n%s" % (username, timestamp, token_id)
obj = hashlib.md5()
obj.update(md5_format_str.encode())
print("token format:[%s]" % md5_format_str)
print("token :[%s]" % obj.hexdigest())
return obj.hexdigest()[10:17], timestamp

标签:format,token,encoded,before,Strings,md5,hashing
From: https://www.cnblogs.com/beichengshiqiao/p/16967453.html

相关文章