md5 hash for file without File Attributes
Posted
by Glennular
on Stack Overflow
See other posts from Stack Overflow
or by Glennular
Published on 2010-04-28T15:50:03Z
Indexed on
2010/04/28
15:53 UTC
Read the original article
Hit count: 360
Using the following code to compute MD5 hashs of files:
Private _MD5Hash As String
Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim md5hash() As Byte
md5hash = md5.ComputeHash(Me._BinaryData)
Me._MD5Hash = ByteArrayToString(md5hash)
Private Function ByteArrayToString(ByVal arrInput() As Byte) As String
Dim sb As New System.Text.StringBuilder(arrInput.Length * 2)
For i As Integer = 0 To arrInput.Length - 1
sb.Append(arrInput(i).ToString("X2"))
Next
Return sb.ToString().ToLower
End Function
We are getting different hashes depending on the create-date and modify-date of the file. We are storing the hash and the binary file in a SQL DB. This works fine when we upload the same instance of a file. But when we save a new instance of the file from the DB (with today's date as the create/modify) on the file-system and then check the new hash versus the MD5 stored in the DB they do not match, and therefor fail a duplicate check.
How can we check for a file hash excluding the file attributes? or is there a different issue here?
© Stack Overflow or respective owner