bash Shell sha1($salt.$password) 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11708951/
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-09-18 02:54:07  来源:igfitidea点击:

Shell sha1($salt.$password) error

bashstring-concatenationcommand-substitution

提问by user1524529

I try to do something like this directly on my console as some testruns :

我尝试在我的控制台上直接做这样的事情作为一些测试:

It does not seem to work.. any idea what is the mistake I am doing

它似乎不起作用..不知道我在做什么错误

salt="3245678906789045689"
password="12321312231"
blub=`sha1($salt.$password)`
-bash: command substitution: line 1: syntax error near unexpected token `$salt.$password'
-bash: command substitution: line 1: `sha1($salt.$password)'

It throws out an errors this is what I intend to do at the end:

它抛出一个错误,这是我最后打算做的:

echo $blub

Can some one please helpout as to what is the error I am doing?

有人可以帮忙看看我在做什么错误吗?

回答by Theodros Zelleke

Probably you want to use SHA1 from the OpenSSL package. This should be already installed on your system.

可能您想使用OpenSSL 包中的SHA1 。这应该已经安装在您的系统上。

echo -n "$salt$password" | openssl dgst -sha1
(stdin)= a1b2ce5a82e18f454db6b2d6ee82533914f90337

To capture just the sha1-digest:

只捕获 sha1-digest:

blub=`echo -n "$salt$password" | openssl dgst -sha1 |awk '{print $NF}'`
echo $blub
a1b2ce5a82e18f454db6b2d6ee82533914f90337

I assume you copied your code from PHP. There functions are called with brackets and the .-Operator concatenates strings. In that interpretation my code is the exact equivalent of your code in BASH.

我假设您从PHP复制了您的代码。使用方括号调用函数,.-Operator 连接字符串。在这种解释中,我的代码与您在BASH中的代码完全等效。

回答by Joost Hoogendoorn

I didn't came across a lot of explanations on how to easily do a SHA checksum in bash and put it in a variable in the right way, at the same time we should not use sha1 anymore, but something more difficult to bruteforce, like sha512:

我没有遇到很多关于如何在 bash 中轻松执行 SHA 校验和并以正确的方式将其放入变量的解释,同时我们不应该再使用 sha1,但有些更难以暴力破解,例如sha512:

dash=`echo -n $password$salt|sha512sum` ##gives hash with trailing dash
read hash rest <<< "$dash" ##removes trailing dash and gives $hash
echo $hash
6555b9d2331203634664f48f604b59372b32badbc115ec6b2586890ef4d3a6b6816d84cc424cdfc538f6a7ccf664c90caeeb942dbf7953051bb1d7414a191c51