Click here to Skip to main content
13,597,784 members
Rate this:
Please Sign up or sign in to vote.
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#?
Posted 2-Dec-12 16:38pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Franklin Barnett 3-Dec-12 1:19am
Perhaps it might be possible to use some sort of alternative of "Sandboxie"? Essentially that program allows you to run programs in a sandbox so that they don't save files to the hard drive, which is handy for downloading sketchy-looking programs. I'll look into this...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180621.3 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100