views:

24

answers:

1

WinForms / C#

My application allows the user to specify 1) additional information for 2) a given file, both of which are uploaded to the server. There are two isolated uploads: first the file, and (maybe much) later the metadata.

Please assume the file to be always unchanged and available (to the code).

When the metadata is uploaded, I need to ensure it is associated with its given file without again uploading that file (they're big files).

My plan is to use an MD5 hash of the following three attributes of the file:

  • contents
  • size
  • created date

The hash will accompany both the file and the metadata in their respective uploads (and eventual persistence).

What smarter solution am I overlooking?

A: 

You may consider using SHA-1 or even better SHA-256 instead of MD5, since MD5 hashes may not be unique enough: it is possible to generate a file with size and MD5 hash matching those of other file. See, for example, MD5 vulnerability.

Upd: if file uniqueness is not strictly important, you may find much more convenient to just generate an auto-incremented id during upload.

Sergii Volchkov
Kudos on the mention of the other algorithms. I'm considering them. Re: the ID -- I don't have a datastore locally, so that solution unfortunately doesn't fit.
lance