I'm trying to compare hashes generated by SQL Server HASHBYTES()
with hashes generated with python's hash()
(or hashlib
) function. For both functions, the same algorithm is used. The problem is I don't know SQL's seed so I cant generate the same output using python. Is there a way to set SQL's seed? I wasn't able to find any information related to it.
Sql-server – SQL Server hashbytes seed
hashingpythonsql server
Related Question
- Sql-server – a scalable way to simulate HASHBYTES using a SQL CLR scalar function
- Sql-server – the fastest way to convert many nullable ints 1:1 to a binary string
- Sql-server – How to know what hashing algorithm SQL Server used to decrypt the encrypted data when using the function DECRYPTBYPASSPHRASE
- Sql-server – Run SQL query with python in SQL Server raises error: SqlSatelliteCall error: Unsupported input data type in column
Best Answer
I am able to get identical results between python and T-SQL code with the MD5 algorithm. For example, the
NO COLLUSION
string hashes to0x5CA1A58C070F24EF1D4D2900E5727F37
on both platforms.Example T-SQL code:
Example Python code:
I'm not an encryption expert, but it's not clear to me what you mean by "SQL's seed". The MD5 algorithm doesn't appear to call for a random number to be added by the implementer. Such an algorithm would be quite inconvenient because it would result in the same problem that you're running into right now: different implementations of the same hashing algorithm would give different results for the same input.