因为 MD5 模块在 python3 中被移除,所以在这里记录一下python3 中使用 hashlib 模块进行 MD5 的流程。

import hashlib

# 待加密信息
str = 'test'

# 创建md5对象
md5 = hashlib.md5()

# 此处必须声明encode
md5.update(str.encode(encoding='utf-8'))

print('原文: ' + str)
print('MD5: ' + md5.hexdigest())
print('MD5 二进制' + md5.digest())

顺便记录一下 python2 的 MD5 吧:

import md5

src = 'this is a md5 test.'

m1 = md5.new()
m1.update(src.encode(encoding='utf-8'))

print(m1.hexdigest())
Last modification:November 22nd, 2019 at 10:09 am
If you think my article is useful to you, please feel free to appreciate