import hashlib
# md5算法
md5 = hashlib.md5()
md5.update('how to use md5 in python hashlib?'.encode('utf-8'))
print(md5.hexdigest())
# sha1算法
sha1 = hashlib.sha1()
sha1.update('how to use sha1 in'.encode('utf-8'))
sha1.update('python hashlib?'.encode('utf-8'))
print(sha1.hexdigest())
# 生成md5加密字符串的用法
def calc_md5(password):
md5 = hashlib.md5();
md5.update(password.join('handkoo').encode('utf-8'))
return md5.hexdigest()
b = input("请输入密码...")
md = calc_md5(b)
print("-->",md)
c = input("请再次输入密码...")
print(md==calc_md5(c))
运行的结果: