Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to update files with MD5 hash in C#

What I have tried:

how to update files with MD5 hash in C#
Posted
Updated 17-Aug-19 19:52pm
Comments
Dave Kreskowiak 17-Aug-19 10:11am    
You're going to have to describe what you mean by "update files with MD5 hash". That makes no sense at all on its own.
Richard Deeming 22-Aug-19 10:01am    
Once again for those in the cheap seats:

Help us to help you: provide a complete description of the problem, with any relevant parts of your code, and the full details of any errors.

If you're just going to type a single terse sentence three times, then type it in to Google's search box, not the "Ask a question" box.

Files don't "have" an MD5 value, it's one of several values you can obtain by passing the file contents as a binary stream through a specific hashing algorithm - in this case the algorithm is MD5
If you change the file content the MD5 (or SHA, or CRC) value will be different - you can't force a file to have a specific MD5 value at all, all you can do is calculate the new value for the new data content.
 
Share this answer
 
Comments
MadMyche 17-Aug-19 11:20am    
+5Basically what I was going to write... Except on the second part I was going to add in that Excel would throw a "Circular Reference Error" on this :)
1. Create an MD5 hash of the file contents: create md5 hash - Google Search[^].
2. Attach the hash data to the file in whichever way you wish.
 
Share this answer
 
There are 2 basic methods of doing this

External Reference Method
This is the easiest way to implement
1. Open the file as a memory stream
2. Retrieve the Message Digest
3. Save filename and MD in external file or database

Wrapper/Header Method
This is more complex, and requires a program to parse the files it creates to retrieve and validate.
This is similar to how files are attached to emails.
1. Same
2. Same
3. Create a new memory stream
4. Populate new stream with the MD and the file contents
5. Save new memory stream as new file
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900