Hashing passwords in shell (sha512) breaks the line. How to get a result in one line?
The script for hashing:
password="abc123"
hashPassw="$(/bin/echo -n "${password}" | openssl dgst -binary -sha512 | openssl enc -base64)"
echo "${hashPassw}"
Output is (why breaks the line?):
xwtd2ev7b1HQnUEytxcMnSB1CnhS8AaA9lZY8DEOgQBW5nY8NMmgCw6UAHb1RJXB
afwjAszrMSA5JxxDRpUH3A==
Should be one line:
xwtd2ev7b1HQnUEytxcMnSB1CnhS8AaA9lZY8DEOgQBW5nY8NMmgCw6UAHb1RJXBafwjAszrMSA5JxxDRpUH3A==
From the OpenSSL Wiki for enc
.
To suppress this you can use in addition to -base64 the -A flag. This will produce a file with no line breaks at all.
So adding the additional -A
flag will do the trick.
password="abc123"
hashPassw="$(/bin/echo -n "${password}" | openssl dgst -binary -sha512 | openssl enc -A -base64)"
echo "${hashPassw}"
Which outputs
xwtd2ev7b1HQnUEytxcMnSB1CnhS8AaA9lZY8DEOgQBW5nY8NMmgCw6UAHb1RJXBafwjAszrMSA5JxxDRpUH3A==
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With