question

Sharma avatar image
Sharma asked

How to generate hexadecimal number for files and store them in table with file name like MD5 do?

I want to check application files that these are correct or not through SQL code , I know about MD5 that we can generate hexadecimal number through MD5 and then check if any mismatch but I want to implement this through SQL code. I will store correct file version in database table and for checking purpose on application lo-gin I will check these version with existing application file version. Also suggest that this will be current approach or not. Please suggest something?
t-sql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
WilliamD avatar image
WilliamD answered
You could use the [HASHBYTES()][1] function to create an MD5 hash of a value to check against. However, I can't understand why you'd want to do that in T-SQL instead of in the client software (that is where you are wanting to do the check anyway if I understand correctly). [1]: http://msdn.microsoft.com/en-us/library/ms174415(v=SQL.90).aspx
7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

You can pass a `varbinary` data to the `HASHBYTES()` function. Unfortunatelly the `HASHBYTES()` function can process maximum 8000 bytes. But anyway as @WilliamD wrote, this is kind of operation to be done on the client side and only the hash should be sent to the SQL Server and then Compared. If the files will be very huge, you will have to send all the bytes over the network to be processed by the SQL Server what is not a good idea.
1 Like 1 ·
William, HASHBYTES() function generate MD5 hash value for string value but I want to generate MD5 hash value for set of files not strings. Please look this link- http://www.fourmilab.ch/md5/
0 Likes 0 ·
`HASHBYTES()` can take a binary value too, though I still don't see the benefit of doing this on the DB side instead of the client software that is loading these files anyway.
0 Likes 0 ·
This is an desktop application so for security purpose I want to store these information in database so user can not change or delete the files.
0 Likes 0 ·
Then as I said, you can hash the byte value of the file itself and store that. You stated in the question that you would load a valid hex value from a table and compare it at startup. You are doing a hex comparison on the client side of client side data against a fixed value in a table. It still sounds like a process that should be done in the client app.
0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.