對字符串hashlib加密
注意兩點巨坑
1.在py2中 不用對字符encode()編碼,py3中必須encode()編碼否則sha1.hexdigest()答案將不是你想要的。
2.在py3中 必須對map使用list 或tuple或循環輸出才會得到正確答案。
在python2中正確方法
import hashlib
token = "sw7v82sf9hvw"
lis = [token,'1544002201','129793960']
lis.sort()
sha1 = hashlib.sha1()
map(sha1.update,lis)
hashcode = sha1.hexdigest()
print hashcode
在python3中正確方法
import hashlib
token = "sw7v82sf9hvw"
lis = [token,'1544002201','129793960']
lis.sort()
sha1 = hashlib.sha1()
list(map(sha1.update,[x.encode() for x in lis ]))
hashcode = sha1.hexdigest()
print(hashcode)
