Solved

Shred (Secure Delete) a file in NTFS

Posted on 2011-03-07
9
825 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:RNMisrahi
  • 4
  • 3
  • 2
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 35061433
0
 
LVL 11

Assisted Solution

by:lenordiste
lenordiste earned 200 total points
ID: 35061561
Your code is rewriting random data inside a file making the assumption that the OS will actually write the data in place where the file is located. It probably works for some "old" file systems like FAT32 but it sure won't work for NTFS. I don't think this can be achieved without wiping the whole drive.
0
 

Author Comment

by:RNMisrahi
ID: 35061604
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 35061684
> 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
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:RNMisrahi
ID: 35061736
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?

0
 
LVL 11

Expert Comment

by:lenordiste
ID: 35061759
there's either no guarantee that they do work or they are written using a low level language
0
 

Author Closing Comment

by:RNMisrahi
ID: 35061842
Good to know what can and cannot be done.
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 35061845
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.
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 35061856
I've never workd with Delphi, but I know for sure this cannot be achieved in Java or C#.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now