NibblyPig
NibblyPig

Reputation: 52932

C# completely delete a file so that it cannot be retrieved

We have a bit of software that retrieves a file from a client, unencrypts it, processes it, encrypts the results, and sends it back.

We use PGP keys (our private to decrypt, their public to encrypt).

However it occurs to me that although we delete the file after we've processed it, it may be possible in theory to use an undelete tool to get it from the hard disk.

At the moment we use the gpg2.exe program as part of gpg4win to to the pgp decryption so I am not sure we can decrypt it directly to memory so it never touches the hard disk.

Is there a simple way to ensure it's completely gone for good when deleting it?

Upvotes: 0

Views: 190

Answers (3)

Yes, it's trivial to both undelete the file and capture it on-the-fly as it's being written. So the safer approach is to use an OpenPGP library to perform all operations in memory (unless you have huge files that just don't fit into memory).

You need to remember that memory is also swapped to disk so if you have a top-secret data, your task becomes more complicated - you would need to create memory blocks that are not swapped, and somehow use them from .NET.

There's one more complication - if your application decrypts the data, then it has a private key nearby. There's a good chance for the attacker to steal the encryption key and then steal encrypted files and decrypt them.

So your main problem is outside of the disk - it's in ensuring security of the computer system in whole.

Upvotes: 0

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

You can use Wipe utility (http://wipe.sourceforge.net/) to, hm, wipe the unencrypted data.

Upvotes: 0

CompuChip
CompuChip

Reputation: 9232

You could check if the gpg program allows getting the output from stdout instead of writing it to a file, so it doesn't get written to disk. Possibly there is also a C# or C++ library that could do the same.

If you have to use an intermediate file, you can make it a bit harder by overwriting the contents with random data a few times before deleting it, or using a specialised shredder tool to delete it.

As an aside: Note that if you are paranoid enough to worry about someone using special software to recover deleted data, you may also want to worry about fragments of the data remaining in RAM.

Upvotes: 2

Related Questions