Hash中的salt
在密码学中,salt是随机数据,作为单向函数的额外输入,用于加密数据,如密码。
散列:散列将任何数量的数据转换为一个固定长度的散列,不能被逆转。
BCrypt算法
# pip install bcrypt
import bcrypt
# Declaring our password
password = b'wwsPassword'
# Adding the salt to password
salt = bcrypt.gensalt()
# Hashing the password
hashed = bcrypt.hashpw(password, salt)
# printing the salt
print("Salt :")
print(salt)
# printing the hashed
print("Hashed")
print(hashed)
'''
Salt :
b'$2b$12$keztAtu66dUoC3GwApT9aO'
Hashed
b'$2b$12$keztAtu66dUoC3GwApT9aOva4AGMuqnSfuwHhBT9/fvpi08gWCPd2'
'''
hashlib模块
Python hashlib模块是一个方便对消息进行散列的接口。它包含许多方法,可以处理将任何原始信息散列成加密格式。这个模块的主要目的是在一个字符串上使用哈希函数,并对其进行加密,这样就很难解密了。哈希库用于创建一个哈希表。散列表是一种数据结构,旨在通过一组条目进行搜索,每个条目都由一个唯一的密钥来识别。
#pip install hashlib
import hashlib
# Declaring Password
password = 'wwsPassword'
# adding 5gz as password
salt = "5gz"
# Adding salt at the last of the password
dataBase_password = password+salt
# Encoding the password
hashed = hashlib.md5(dataBase_password.encode())
# Printing the Hash
print(hashed.hexdigest())
'''
374731d38a6b21d806beebc37a3b8032
'''