import:: import hashlib doc:: hashlib


使用

import hashlib
 
# 写法一
m = hashlib.sha256()
m.update(b"hello world")
m.digest() # 返回: b'\x9f\x08=NGM\x93\x91O6m\x8f\x97\xd6\x9fw'
m.hexdigest() # 返回: '9f083d4e474d93914f366d8f97d69f77'
 
# 写法二
hashlib.sha256(b"hello world").hexdigest()
 
# 写法三: new 方法, 可以自定义指定加密方式
m = hashlib.new("sha256")
m.update(b"hello world")
m.hexdigest() # 返回: '9f083d4e474d93914f366d8f97d69f77'