1. 什么是hash
hash是一種算法,該算法接受一系列的數(shù)據(jù),經(jīng)過運(yùn)算會得到一個(gè)hash值,
hash值具備三大特性:
1. 只要傳入的內(nèi)容一樣,那么得到的hash值一定是一樣
2. 只要采用hash算法固定,無論傳入的內(nèi)容多大,hash值的長度是固定

3. hash值不可逆,即不能通過hash值逆推出內(nèi)容

2. 為何要用hash

特性1+2=>文件完整性校驗(yàn)
特性3==>

import hashlib

m=hashlib.md5()
m.update('你好'.encode('utf8'))
m.update('hello'.encoding('utf8'))
print(m.hexdigest())

m=hashlib.sha512()
m.update('你好'.encode('utf8'))
m.update('hello'.encoding('utf8'))
print(m.hexdigest())


pwd=input('password>>> ').strip()
m=hashlib.md5()
m.update('天王蓋地虎'.encode('utf-8'))
m.update(pwd.encode('utf-8'))
m.update('一行白鷺上青天'.encode('utf-8'))
print(m.hexdigest())
View Code