简体   繁体   English

sha1密码哈希linux

[英]sha1 password hash linux

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? 所以,例如,如果我的密码是“你好”,我需要输入什么命令到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! 谢谢! :) :)

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 $1}'

This will feed your output through awk and give you only the 1st column. 这将通过awk输出您的输出,并仅为您提供第一列。 Result: The correct sha1 for "hello" 结果:正确的sha1为“你好”

aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

Hope this helps someone. 希望这有助于某人。

The password format may be different in different applications. 密码格式在不同的应用程序中可能不同。 For example, for /etc/passwd you can generate a SHA-256 password with: 例如,对于/etc/passwd您可以使用以下命令生成SHA-256密码:

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

For passwords in LDAP (eg for slapd.conf ), it may be: 对于LDAP密码(例如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. 您需要知道应用程序的确切密码格式以及密码的生成方式。

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

将YOUR_TEXT与您必须散列的文本进行交换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM