Link to home
Start Free TrialLog in
Avatar of RNMisrahi
RNMisrahiFlag for United States of America

asked on

Shred (Secure Delete) a file in NTFS

I need a secure way to delete a file.
I've gone through the standard procedure of overwriting 6 times with 0 and 255 bytes and then with random data, but when I scan the disk, I see a copy of the information is there.
I've used:

  public static void secureDelete(File file, byte[] b) throws IOException {
    if (file.exists()) {
      long length = file.length();
      SecureRandom random = new SecureRandom();
      RandomAccessFile raf = new RandomAccessFile(file, "rws");
      raf.seek(0);
      raf.getFilePointer();
      byte[] data = new byte[50];
      int pos = 0;
      while (pos < length) {
        random.nextBytes(data);
        raf.write(data);
        pos += data.length;
      }
      raf.close();
      file.delete();
    }
  }

using as 'b' zeros, 255 and random numbers.
It works for FAT but not for NTFS
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RNMisrahi

ASKER

If it is true that on an NTFS Secure Delete is impossible (and you guys may be right), how come there are some applications that do that? I mean, they don't wipe all the empty space. So how do they do that? Or is it that there is no guarantee that they do work?
> I mean, they don't wipe all the empty space.

do you know that for a fact?
Native applications can operate at a much lower level than Java can
I'm ready to accept the fact that it is impossible to guarantee secure deleting on an NTFS, but I cannot imagine these utilities wiping all the empty space on a 1 TB disk in a few seconds. I have a 360GB disk, over half of it is free and when they delete (as far as I can see so far), the info is not there anymore. When I use an app such as HxD to scan the surface for a specific string, it is not there anymore. The HxD app takes hours to scan the whole disk.

But if Java cannot do this, can this be done with C# or Delphi?

there's either no guarantee that they do work or they are written using a low level language
Good to know what can and cannot be done.
look at the comment from theUnhandledException (one of the last comments) since it's spot on about your problem:
http://stackoverflow.com/questions/4147775/securely-deleting-a-file-in-c-net

as he advises, the solution may be to reconsider the problem and encrypt the files you are writing to disk with a dynamic encryption key.
I've never workd with Delphi, but I know for sure this cannot be achieved in Java or C#.