Tags

, , ,

A few days ago, I wrote (Secure File Delete – Serious FUD)about the FUD being circulated by security applications for secure deletion of files. In order to convince you that overwriting the file once is enough – as compared to fifteen times as marketed by some applications, given below is the code that proves this point.

package bsp.filedelete;

import java.io.RandomAccessFile;

public class SecureErase
{
    public static void overwriteFile(File f, char oc)
    {
        try {
            RandomAccessFile pw = new RandomAccessFile(f, "rw");
            long len = f.length();
            for ( long x = 0; x < len; x++ ) {
                pw.write(oc);
            }
            pw.close();
        } catch ( FileNotFoundException e ) {
            e.printStackTrace();
        } catch ( IOException e ) {
            e.printStackTrace();
        }
    }
	
    public static void main(String[] args)
    {
        try {
            File f = new File(args[0]);
            overwriteFile(f, '0');
		
            // uncomment the following line when you are convinced that
            // the data has been overwritten completely
            //f.delete();
        } catch ( FileNotFoundException e ) {
            e.printStackTrace();
        } catch ( IOException e ) {
            e.printStackTrace();
        }
    }
}
Advertisements