MD5 与 SHA256
65.1 MD5 与 SHA256
哈希是单向摘要,不能反推原文;相同输入得到相同哈希。
密码存储应使用加盐的强哈希(如 bcrypt),MD5 仅作文件校验示例。
计算 SHA256
import hashlib
text = 'hello'.encode('utf-8')
print(hashlib.sha256(text).hexdigest())
哈希是单向摘要,不能反推原文;相同输入得到相同哈希。
密码存储应使用加盐的强哈希(如 bcrypt),MD5 仅作文件校验示例。
import hashlib
text = 'hello'.encode('utf-8')
print(hashlib.sha256(text).hexdigest())