added secure file deletion, overwriting the file with random data before actual deletion
Update issue 56 Added a method for secure file deletion. We'll possibly have to test this a bit and make sure it actually *is* secure on the filesystems used (vfat for SD card, yaffs2 for phone flash memory by default). This sort of overwrite might be absolutely useless on some filesystems. I also wanted to add an option at first, but this seems reasonably fast and in general it should be what the user wants, so for now it will ALWAYS securely delete. If there is a demand for plain deletion, then options can be added. Update issue 39 A new string: <string name="progress_deletingSecurely">deleting \'%s\' securely...</string>
This commit is contained in:
@@ -20,10 +20,12 @@ import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.math.BigInteger;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.KeyPairGenerator;
|
||||
@@ -1895,4 +1897,24 @@ public class Apg {
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static void deleteFileSecurely(Context context, File file, ProgressDialogUpdater progress)
|
||||
throws FileNotFoundException, IOException {
|
||||
long length = file.length();
|
||||
SecureRandom random = new SecureRandom();
|
||||
RandomAccessFile raf = new RandomAccessFile(file, "rws");
|
||||
raf.seek(0);
|
||||
raf.getFilePointer();
|
||||
byte[] data = new byte[1 << 16];
|
||||
int pos = 0;
|
||||
String msg = context.getString(R.string.progress_deletingSecurely, file.getName());
|
||||
while (pos < length) {
|
||||
progress.setProgress(msg, (int)(100 * pos / length), 100);
|
||||
random.nextBytes(data);
|
||||
raf.write(data);
|
||||
pos += data.length;
|
||||
}
|
||||
raf.close();
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user