I have a file which should be opened in a third-party program. That file is encrypted until it is needed. When the user runs my C# program, it will decrypt the file, open it with the third-party software, then when the software is done, it will re-encrypt the file. The third-party cannot do the encryption and decryption itself.
The problem with this setup is that during the time the third-party program is open, the file is exposed to the world. It can be copied and pasted elsewhere, ruining the purpose of the encryption.
I'd like to fix this flaw. I'm not sure how to prevent the file from being copied. I tried using a virtual file system called Dokan, which will supposedly allow me to change how a file is read or written to. The main problem with it is that I can't figure out how to control the read/write of this file to prevent copying. I think Dokan also requires NTFS filesystems, which I shouldn't assume the end-user has.
Is there another way to control read/write on a file in C#?
Not really. The only option I really see is decrypting the file in-memory and passing that to the third-party application.
The flaw really lies in the fact that the third party application doesn't do the encryption/decryption itself AND doesn't provide a way to pass in the decrypted information.
Found out my issue. Granted the whole scheme is a bit unorthodox, but modifying the target application itself isn't practical.
I ended up revisiting the Dokan solution. Dokan creates a sort of virtual hard drive out of an empty folder or creates a new drive. This time I successfully modified it in the way I want, and now I can control how various applications interact with the file.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)