Question

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?

Was it helpful?

Solution

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

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

To capture just the 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.

OTHER TIPS

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:

dash=`echo -n $password$salt|sha512sum` ##gives hash with trailing dash
read hash rest <<< "$dash" ##removes trailing dash and gives $hash
echo $hash
6555b9d2331203634664f48f604b59372b32badbc115ec6b2586890ef4d3a6b6816d84cc424cdfc538f6a7ccf664c90caeeb942dbf7953051bb1d7414a191c51
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top