python中MD5使用练习

import platform
pv = platform.python_version()
print (pv)

import hashlib

deomo_val = 'a4ec18''

md5_jm = md5_val = hashlib.md5(deomo_val.encode('utf8')).hexdigest()
print ('src_val : %s \nmd5_val : %s' % (deomo_val,md5_val))


f = open('./12.py', 'r')
f_md5 = hashlib.md5()
f_md5.update(f.read().encode('utf8'))

# f = open('./test.log', 'rb')
# f_md5 = hashlib.md5()
# f_md5.update(f.read())

print (f_md5.hexdigest())

 

自建md5加密

# import hashlib
# 
# # m = hashlib.md5()
# # print(m)
# #
# # m.update("hello world".encode("utf-8"))
# # print(m.hexdigest())    #5eb63bbbe01eeed093cb22bb8f5acdc3
# # m.update("zichuan".encode("utf-8"))
# # print(m.hexdigest())    #4fdf7544ca02bf67c8c205bb0e3b56ba
# #
# # m2 = hashlib.md5()
# # m2.update("hello worldzichuan".encode("utf-8"))
# # print(m2.hexdigest())   #4fdf7544ca02bf67c8c205bb0e3b56ba
# 
# s = hashlib.sha256()
# s.update("hello world".encode("utf-8"))
# print(s.hexdigest())    #b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

 

posted @ 2019-07-11 01:59  MTcx  阅读(328)  评论(0编辑  收藏  举报