I've been out of the C# game for a while since I started iPhone stuff, but how can you delete a file completely (so its not stored in memory) and isn't recoverable. If you can't delete it forever can you scramble it up with random data so it is unable to be opened but still exists?
Asked
Active
Viewed 9,193 times
2 Answers
4
It's certainly possible to overwrite a file so that the previous content cannot be recovered. But this has to be done by the drive itself to make sure the correct block is overwritten... C# interacts with the filesystem, not physical blocks, so won't provide any security.
The actual way to ask a drive to securely erase something varies with interface (ATAPI vs SATA, vs USB mass-storage vs SCSI vs firewire), and C# doesn't provide a simple way of commanding at this level.

Ben Voigt
- 277,958
- 43
- 419
- 720
-
How about this, can I scramble the file using encryption to a point where it cant be read at all? There's software to do this already so its possible, how do they do it? – user377419 Jul 25 '10 at 19:04
-
@shorty: If you encrypt the data the FIRST time you write it to the disk, then no one can read the data without the key. If it has ever been stored unencrypted, then the only two ways to prevent recovery are (1) the drive's built-in secure erase or (2) complete physical destruction of the drive. – Ben Voigt Jul 25 '10 at 19:08
-
physical destruction, as in an axe?! sweet! ok, what about secure erase, how can you run that command. I'm assuming C# cant access it. – user377419 Jul 25 '10 at 19:10
-
1An axe might leave pieces big enough to read, if someone has enough time and a hell of a lot of money. Incineration or grinding the disk into dust should work though. As for running the secure erase command, here's one program to do it, along with a paper describing why other methods don't work: http://cmrr.ucsd.edu/people/Hughes/SecureErase.shtml – Ben Voigt Jul 25 '10 at 19:16
-
Please note that even with the secure erase command, you're trusting the drive manufacturer to do something that really overwrites the drive. On some disks, especially new SSDs, this may not happen. – Ben Voigt Jul 25 '10 at 19:19
-
1Haha! Could you share some code to grind/burn a harddrive please? Alright i guess my plan is ruined or too difficult for me :[ tanks anyway you get best answer – user377419 Jul 25 '10 at 19:26
3
sdelete
run this command via Process in c#.
Process p = new Process();
p.StartInfo = new ProcessStartInfo( "cmd", "/c sdelete -p 1 -s -z -q -a 'path/to/director' )
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
sdelete
can be downloaded here

abc123
- 17,855
- 7
- 52
- 82