环境:Python3.6.2 + win10
1.hashlib加密
# 安全哈希算法sha1返回的字符串 from hashlib import sha1, md5 import os import time random_str = lambda: sha1(bytes("%s%s" % (os.urandom(16), time.time()), encoding=‘utf8‘)).hexdigest() print(random_str()) def random_str1(): byt = bytes(‘%s%s‘ % (os.urandom(16), time.time()), encoding=‘utf8‘) sh = sha1(byt) return sh.hexdigest() print(random_str1()) # md5返回的字符串 def md5str(): md = md5(bytes(‘%s%s‘ % (os.urandom(16), time.time()), encoding=‘utf8‘)) return md.hexdigest() print(md5str())
End