呃,今天来看看加密和解密,本文讨论base64和hashlib库:
来看看HASHLIB,他是一种单向摘要出定长字符串的方法:
撸代码:
In [18]: import time,hashlib In [19]: t = int(time.time()) In [20]: t Out[20]: 1495597851 In [21]: md = hashlib.md5(‘test%s‘ %t) In [22]: md.hexdigest() Out[22]: ‘8ed81a627d94055cd34d3e7e1d2fed72‘ In [23]: md = hashlib.md5(‘test%s‘ %t) In [24]: md.hexdigest() Out[24]: ‘8ed81a627d94055cd34d3e7e1d2fed72‘ In [25]: md = hashlib.md5(‘test123%s‘ %t) In [26]: md.hexdigest() Out[26]: ‘554aac9fa6ba5a5821f6a80e840b6b36‘ In [27]: md = hashlib.md5(‘test123%s‘ %t) In [28]: md.hexdigest() Out[28]: ‘554aac9fa6ba5a5821f6a80e840b6b36‘
相同字符串md5加密后的16进制是一致的
接下来看base64
In [29]: import base64 In [30]: base64.b64encode(‘123456‘) Out[30]: ‘MTIzNDU2‘ In [31]: base64.b64decode(‘MTIzNDU2‘) Out[31]: ‘123456‘
可以反向计算的
两者结合使用,嘻嘻嘻
时间: 2024-10-27 02:55:35