title: MD5 Hashes not matching
body: <p>I am trying to match a md5 has (generated through php) to its original value in a SQLExpress database.</p>
  
  <p>I am using the following function in my SQL query</p>
  
  <pre><code>master.sys.fn_varbintohexsubstring(0, HASHBYTES('MD5', 'ID'), 1, 0)
  </code></pre>
  
  <p>Where 'ID' is the field in the database.</p>
  
  <p>However they both seem to return different values for the md5 hash. I have been using '12290' as a static value to test this.</p>
  
  <p>php md5() returns: 0bd81786a8ec6ae9b22cbb3cb4d88179</p>
  
  <p>The following SQL Statement returns the same output:</p>
  
  <pre><code>DECLARE @password VARCHAR(255)
  SET @password = master.sys.fn_varbintohexsubstring(0, HASHBYTES('MD5', '12290'), 1, 0)
  SELECT @password
  </code></pre>
  
  <p>Yet when I run the following statement from the table:</p>
  
  <pre><code>SELECT ID,  master.sys.fn_varbintohexsubstring(0, HASHBYTES('MD5', CONVERT(NVARCHAR(255), ID)), 1, 0) AS temp
  FROM Clients
  ORDER BY ID ASC
  </code></pre>
  
  <p>The 'temp' value matching to the 'ID' value of 12290 returns: 1867dce5f1ee1ddb46ff0ccd1fc58e03</p>
  
  <p>Any help on the matter would be much appreciated!</p>
  
  <p>Thanks</p>