I am trying to create a Hash from an integer using SQL. The purpose of this is to create a function in which I will know if the data received has not been tampered with by the person running the script. I figured I would MD5-hash the integer however I am running into some issues with the MD5 hash not being accurate.
Here is my test code where I try to convert 20 into the MD5
SELECT CONVERT(NVARCHAR(32),HashBytes('MD5', STR(20)),2) as 'MD5'
returns F63258CAB6D44ED830605298043CBEA4 and
SELECT CONVERT(NVARCHAR(32),HashBytes('MD5', '20'),2) as 'MD5'
returns the expected result of 98F13708210194C475687BE6106A3B84
What am I doing wrong with my conversion?
Also I do not have to use MD5. I am open to suggestions of using a different method in which it would be easy for me to decrypt but hard for the average user to reverse-engineer even if they saw the code.