0

My C# WinForms application uses Microsoft® Office Word templates and other file formats to write and print data for reports. Those templates are sent to the users via emails and sharing services.

Is there some sort of signature, hidden property or unique identifier to add it to those template files and the application reads this signature to make sure that the files are the one sent to the user; because it will cause error if, for example, uses a template without the bookmarks ?

I have read about GetFileInformationByHandle function in this post, but I am not sure of the outcome.

Taher
  • 565
  • 1
  • 14
  • 32
  • Perhaps this link can add to your research if you have not yet saw it: Document Fingerprinting https://learn.microsoft.com/en-us/office365/securitycompliance/document-fingerprinting – Zorkind Oct 18 '18 at 19:09

1 Answers1

1

You could use a Hash function to generate a Checksum to verify the file. Hash your template file, and append the checksum to the file. Read this at the end and verify it's the same as the one on your end (remembering to remove the checksum before rehashing the file), to prove the files are identical.

John
  • 598
  • 2
  • 7
  • 22
  • 1
    You could use a GUID Guid newname = Guid.New(); – China Syndrome Oct 18 '18 at 19:16
  • @John I tried this checksum, indeed changing anything in the document template changed the checksum but I guess I will have to save the checksum in other file than the template file may be in an XML file. But, generally, I got the idea. Thanks. – Taher Oct 18 '18 at 20:02
  • 2
    @Tima you could store it in a separate file, or just append it the file and remove it as hashes are constant length. E.g, using SHA256, the hash will always be 32 bytes long. So if you append that to the file, you can read it by using a filestream and this: `filestream.seek(filestream.length - 32, SeekOrigin.Current)` then just read the 32 bytes. – John Oct 18 '18 at 20:30