sha1 密码 哈希 linux

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15626073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:33:36  来源:igfitidea点击:

sha1 password hash linux

linuxbashshellcryptographysha1

提问by Dan

What i want is to be able to get the sha1 hashed value of a particular password.

我想要的是能够获得特定密码的 sha1 散列值。

So for instance if my password was "hello" what command would i need to type into linux to get the sha1 hashed value of hello?

因此,例如,如果我的密码是“hello”,我需要在 linux 中输入什么命令才能获取 hello 的 sha1 散列值?

I tried

我试过

echo -n "hello" | sha1sum

but the value it returned did not give a value that was accepted by the database stored procedure that takes in the hashed value to verify a login(which the issue is not in this stored procedure because we use it all over the place for verfication purposes).

但是它返回的值没有给出一个数据库存储过程接受的值,该过程接受散列值来验证登录(问题不在这个存储过程中,因为我们到处都使用它来进行验证) .

BASICALLY,

基本上,

i just need to know a command to give a string and get back the sha1 hashed value of it

我只需要知道一个命令来给出一个字符串并取回它的 sha1 散列值

Thanks! :)

谢谢!:)

回答by pynexj

The password format may be different in different applications. For example, for /etc/passwdyou can generate a SHA-256 password with:

密码格式在不同的应用程序中可能会有所不同。例如,/etc/passwd您可以使用以下命令生成 SHA-256 密码:

# perl -e 'print crypt("password", q($salt$)), "\n";'
$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1
#

For passwords in LDAP(e.g. for slapd.conf), it may be:

对于LDAP(例如 for slapd.conf)中的密码,它可能是:

# slappasswd -h "{SSHA}"
New password:
Re-enter new password:
{SSHA}bjEe8dPBjyecc7hD1kUhxQUdF9dt4Hya
#

You need to know the exact password format for your application and how the passwords are generated.

您需要知道应用程序的确切密码格式以及密码的生成方式。

回答by Dom

I know this is really old but here is why it did not work and what to do about it:

我知道这真的很旧,但这就是为什么它不起作用以及如何处理它:

When you run the

当你运行

echo -n "hello" | sha1sum

as in your example you get

在你的例子中,你得到

aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d  -

Notice the '-' in the end.

注意末尾的“-”。

The hash in front is the correct sha1 hash for hello, but the dash messes up the hash.

前面的散列是 hello 的正确 sha1 散列,但破折号弄乱了散列。

In order to get only the first part you can do this:

为了只获得第一部分,您可以这样做:

echo -n "hello" | sha1sum | awk '{print }'

This will feed your output through awk and give you only the 1st column. Result: The correct sha1 for "hello"

这将通过 awk 提供您的输出,并只为您提供第一列。结果:“hello”的正确 sha1

aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

Hope this helps someone.

希望这可以帮助某人。

回答by ALI-S0

echo -n YOUR_TEXT | sha1sum | awk '{print }'

exchange YOUR_TEXT with the text you have to hashing it.

将 YOUR_TEXT 与您必须对其进行哈希处理的文本进行交换。