hashilib模块和hmac模块

用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供SHA1,SHA224,SHA256,SHA384,SHA512,MD5算法(SHA512最复杂,最安全)

>>> import hashlib
>>> m = hashlib.md5() # 其它加密算法同理
>>> m.update('666')
>>> m.hexdigest() # 16进制格式hash
'fae0b27c451c728867a567e8c1bb4e53'
>>> m.update('888')
>>> m.hexdigest()
'75e266f182b4fa3625d4a4f4f779af54'
>>> m_new = hashlib.md5()
>>> m_new.update('666888')
>>> m_new.hexdigest()
'75e266f182b4fa3625d4a4f4f779af54'

hmac模块内部对我们创建key和内容再进行处理然后再加密

>>> h = hmac.new(b'Where can I go a little later',b'Go to the hospital')
>>> h.hexdigest()
'8017d0aa2a051905ed8f821c3e2bdce5'

猜你喜欢

转载自www.cnblogs.com/allenzhang-920/p/9279801.html