hashlib的使用场景
对于hashlib中,加123456加密,拆开加密和整体加密,其结果是一样的。
1、明文加密
对于密码加密,可以使用加盐的操作来提高安全性。
import hashlib
def make_hash_password(the_str:str):
if not isinstance(the_str,str):
raise ValueError('传递的值必须是字符串')
if len(the_str)<3:
raise ValueError('加密的字符串必须不短于3')
sha_256 = hashlib.sha256()
dic = {
0:'2H&',
1:'g$9',
2:'&Z0',
3:'p@5', #0-3 加3个字符
4:'Bh6*',
5:'K3#2w',
6:'J0$9dW', #4-6 加对应的数值的字符数
'last':'h9@3K6Z' # 7或以上,加7个字符数
}
strs = ''
for i in range(len(the_str)):
key = dic.get(i,dic.get('last'))
sha_256.update(key.encode('utf-8'))
sha_256.update(the_str[i].encode('utf-8'))
strs+=key
strs&#