use of run.wallet.common.delete.ciphers.Trivium in project run-wallet-android by runplay.
the class SecureDeleteFile method delete.
/**
* Securely delete a file.
*
* Currently, there is only 1 pass that overwrites the file first
* with a random bit stream generated by Trivium.
*
* @param file
* @return true if this File was deleted, false otherwise.
*/
public static boolean delete(File file) {
// Log.e("FILEDEL", file.getAbsolutePath());
if (file.exists()) {
SecureRandom random = new SecureRandom();
Trivium tri = new Trivium();
try {
RandomAccessFile raf = new RandomAccessFile(file, "rw");
FileChannel channel = raf.getChannel();
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
byte[] key = new byte[10];
byte[] nonce = new byte[10];
random.nextBytes(key);
random.nextBytes(nonce);
tri.setupKey(Trivium.MODE_DECRYPT, key, 0);
tri.setupNonce(nonce, 0);
int buffersize = 1024;
byte[] bytes = new byte[1024];
// overwrite with random numbers
while (buffer.hasRemaining()) {
int max = buffer.limit() - buffer.position();
if (max > buffersize)
max = buffersize;
// random.nextBytes(bytes);
tri.process(bytes, 0, bytes, 0, max);
buffer.put(bytes, 0, max);
}
buffer.force();
buffer.rewind();
} catch (FileNotFoundException e) {
Log.d(TAG, "FileNotFoundException", e);
} catch (IOException e) {
Log.d(TAG, "IOException", e);
} catch (ESJException e) {
Log.d(TAG, "ESJException", e);
}
// return true;
return file.delete();
}
return false;
}
Aggregations