--- UPDATED with better console stuff and now using the crypto random number generator.
I know that some of you have found yourself in that situation that requires you to delete something from your hard drive permanently, thus rendering your data unrecoverable.
Well, there isn't a good way to do that through C# without some tomfoolery... so I hereby present you with SuperDelete
. This code will permanently delete whatever file you pass in, overwriting the existing data with cryptographically random numbers a specified number of times before deleting the file. This renders the previously existing data pretty much useless to anyone.
As long as data is being flushed to the drive after each file write (hence the foreach over the FileStream), and your system doesn't have some sort of advanced write-caching in place that will cache data over multiple file opens and closes, your data will be as good as dead once this code is finished with it.
The recommended overwrite of 10 times is to cover the nominal servo-positioning errors that occur in all hard drives, however you can push this up to whatever value you want to make yourself feel secure.
I also recommend that you read this article on data storage and recovery: http://wipe.sourceforge.net/secure_del.html
static byte buffer = new byte;
For the complete program, including the disabling of write-caching, please purchase my Super Delete application.