You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不同实现下Argon2哈希值不匹配问题排查求助

Argon2哈希结果不一致问题排查

我使用Python Argon2库编写代码,对邮箱地址example@example.com进行哈希测试:

import argon2
print(argon2.argon2_hash("example@example.com", salt="1558cc06add8a1023cbfa527c5af29fe", t=16, m=8, p=1, buflen=16, argon_type=argon2.Argon2Type.Argon2_i).hex())

得到结果:

f62830118f962095caad9cdbc64e0bc2

随后我使用Debian Bullseye系统的Argon2命令行工具(截至2022年11月17日已更新至最新版)执行:

echo -n example@example.com | argon2 1558cc06add8a1023cbfa527c5af29fe -t 16 -m 8 -p 1 -l 16 -r

注:echo使用-n参数避免添加换行符

得到结果:

4955d9263eb65cd9071aaea6bc60a93e

接着用Go语言实现:

package main

import (
    "fmt"
    "encoding/hex"
    "golang.org/x/crypto/argon2"
)

const argon2Iterations uint32 = 16
const argon2Memory uint32 = 8
const argon2Parallelism uint8 = 1
const argon2KeyLength uint32 = 16

func main() {
    fmt.Println(hex.EncodeToString(argon2.Key([]byte("example@example.com"), []byte("1558cc06add8a1023cbfa527c5af29fe"), argon2Iterations, argon2Memory, argon2Parallelism, argon2KeyLength)))
}

结果为:

330bb2088c87342a4abe1a987940bbec

我还测试了两个在线哈希生成器,二者结果均与Go语言实现一致:

330bb2088c87342a4abe1a987940bbec

我猜测Go语言及在线工具的结果是正确的,可能是Python或命令行工具的使用方式有误,但检查参数后未发现差异(均使用Argon2i算法,迭代次数、内存等参数一致),为何哈希值会不同?


内容的提问来源于stack exchange,提问作者David Hicks

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 22:46:03