上課了:Python 加密解密演算法

yuyu5發表於2017-06-09

來看看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' 可以反向計算的

相關文章