使用Argon2密钥绑定功能,这可以让Argon2生成一个长度为32字节的输出,并且附加一个密钥以生成更长的输出。以下是Python代码示例:
import argon2
# 定义输入参数
password = b'my_password'
salt = b'my_salt'
key = b'my_key' # 这个key可以是您自己生成的
# 定义Argon2配置
hash_len = 32
memory_cost = 1024
time_cost = 2
parallelism = 2
# 使用密钥绑定功能
argon2_hash = argon2.PasswordHasher(
hash_length=hash_len,
memory_cost=memory_cost,
time_cost=time_cost,
parallelism=parallelism,
salt_len=len(salt),
secret=key # 把key作为“secret”传递
)
# 生成哈希值
hash_value = argon2_hash.hash(password, salt)
上一篇:Argon2的最大输入和输出长度
下一篇:Argon2id 十六进制转哈希