Secure File Deleting in C
I need to securely delete a file in C, here is what I do:
- use
fopento get a handle of the file - calculate the size using
lseek/ftell - get random seed depending on current time/or file size
- write (size) bytes to the file from a loop with 256 bytes written each iteration
fflush/fclosethe file handle- reopen the file and re-do steps 3-6 for 10~15 times
- rename the file then delete it
Is that how it’s done? Because I read the name “Gutmann 25 passes” in Eraser, so I guess 25 is the number of times the file is overwritten and ‘Gutmann’ is the Randomization Algorithm?
You can’t do this securely without the cooperation of the operating system – and often not even then.
When you open a file and write to it there is no guarantee that the OS is going to put the new file on the same bit of spinning rust as the old one. Even if it does you don’t know if the new write will use the same chain of clusters as it did before.
Even then you aren’t sure that the drive hasn’t mapped out the disk block because of some fault – leaving your plans for world domination on a block that is marked bad but is still readable.
ps – the 25x overwrite is no longer necessary, it was needed on old low density MFM drives with poor head tracking. On modern GMR drives overwriting once is plenty.