xyaonline xyaonline - 3 months ago 9x
SQL Question

How to select SHA1 hash values correctly?

I need to extract SHA1 Passwords from a Microsoft SQL Server database in order to use them in an external system.

When I do a simple select query for a known password, I get this result (password is "password"):


But it should be

Any idea how to select it to get the expected value

hvd hvd

SHA1 hashing is done on bytes, not on characters, therefore it's important to make sure that the conversion from characters to bytes is done with an agreed upon encoding.

5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 is the SHA1 hash of password encoded in ASCII/UTF-8.

5b9febc2d7429c8f2002721484a71a84c12730c7 is the SHA1 hash of password encoded in UTF-16-BE.

To fix this, pick one encoding, and change whatever code is using the other encoding to match.