Reputation: 4338
I need to replace some plain text passwords with SHA256 Base64 passwords.
Apparentely the hash generated by the database functions does not match with the ones used by the application. For example: my application uses this function for generating the hash:
$ echo -n "admin" | openssl dgst -sha256 -binary | openssl base64
jGl25bVBBBW96Qi9Te4V37Fnqchz/Eu4qB9vKrRIqRg=
Now, the same password with the database:
select TO_BASE64(SHA2('admin',256));
OGM2OTc2ZTViNTQxMDQxNWJkZTkwOGJkNGRlZTE1ZGZiMTY3YTljODczZmM0YmI4YTgxZjZmMmFiNDQ4YTkxOA==
As you can see it does not match! Any help ?
My DB Version: Server version: 10.0.23-MariaDB MariaDB Server
Upvotes: 2
Views: 4590
Reputation: 11
echo -n "admin" | openssl dgst -sha256 | awk '{ print $2; }' | openssl base64
Upvotes: 1
Reputation: 3690
Remove -binary from echo -n "admin" | openssl dgst -sha256 -binary | openssl base64
and you will get the same results.
with -binary
it returns the actual binary data of the sha256 string, if thats what you want, you have to convert result from SHA2('admin',256)
to binary and then apply TO_BASE64
to it.
Upvotes: 3