Reputation: 381
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==
Upvotes: 24
Views: 33969
Reputation: 656
To remove the new line in openssl use the flag -A.
Example:
echo "password" | openssl base64 -A
Upvotes: 1
Reputation: 4737
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==
Upvotes: 30
Reputation: 70263
Why do you think it should be one line? Base64 does wrap lines.
If you insist, your question boils down from "SHA512 SSL Base64 whatever" to "how do I remove newlines", for which there are many ways,
tr -d '\n'
being only one of them.
Upvotes: 14