有人知道如何在 Linux 上使用命令行生成哈希吗? 我必须使用 SHA1 + salt= 密码:Cat Salt:XN10Zj2c 生成哈希 和 MD4= 密码的哈希值:Cat
谢谢您的帮助!
对于 SHA1 + salt,我尝试过= echo -n "$XN10Zj2c$Cat" | openssl dgst -sha1
这里的问题是没有通用的方法来对密码和盐进行哈希处理。您很可能需要模仿
crypt
命令行工具,因为它不包含这些算法(因此我使用 -1 和 -2 作为算法标识符)。
例如:
#!/bin/bash
# Your password and salt
password="your_password_here"
salt="your_salt_here"
# Specify the algorithm: -1 for MD4, -2 for SHA-1
algorithm_specifier="-2" # Change this to -1 for MD4
# Function to hash with SHA-1
hash_sha1() {
local pass="$1"
local salt="$2"
echo -n "$pass$salt" | openssl dgst -sha1
}
# Function to hash with MD4
hash_md4() {
local pass="$1"
local salt="$2"
echo -n "$pass$salt" | openssl dgst -md4
}
# Check for the specified hashing algorithm
if [ "$algorithm_specifier" == "-2" ]; then
# SHA-1 hashing
sha1_hash=$(hash_sha1 "$password" "$salt")
echo "$algorithm_specifier$$salt$$sha1_hash"
elif [ "$algorithm_specifier" == "-1" ]; then
# MD4 hashing
md4_hash=$(hash_md4 "$password" "$salt")
echo "$algorithm_specifier$$salt$$md4_hash"
else
echo "Invalid algorithm specifier."
fi
但是,请注意,您不应使用这些旧的、损坏的哈希值 也不应使用 SHA-2 或 SHA-3 等较新的哈希值。原因是您应该使用具有高迭代计数或工作因子的 PBKDF(例如 PBKDF2 或 Argon2),并且最好使用 16 字节随机盐。这些函数有时也被称为“密码哈希”,这是有充分理由的;它们提供额外的保护,防止暴力破解和字典攻击。