use of com.amaze.filemanager.database.models.EncryptedEntry in project AmazeFileManager by TeamAmaze.
the class EncryptDecryptUtils method findEncryptedEntry.
/**
* Queries database to find entry for the specific path
*
* @param path the path to match with
* @return the entry
*/
private static EncryptedEntry findEncryptedEntry(Context context, String path) throws GeneralSecurityException, IOException {
CryptHandler handler = new CryptHandler(context);
EncryptedEntry matchedEntry = null;
// find closest path which matches with database entry
for (EncryptedEntry encryptedEntry : handler.getAllEntries()) {
if (path.contains(encryptedEntry.getPath())) {
if (matchedEntry == null || matchedEntry.getPath().length() < encryptedEntry.getPath().length()) {
matchedEntry = encryptedEntry;
}
}
}
return matchedEntry;
}
use of com.amaze.filemanager.database.models.EncryptedEntry in project AmazeFileManager by TeamAmaze.
the class EncryptDecryptUtils method startEncryption.
/**
* Queries database to map path and password.
* Starts the encryption process after database query
*
* @param path the path of file to encrypt
* @param password the password in plaintext
*/
public static void startEncryption(Context c, final String path, final String password, Intent intent) throws Exception {
CryptHandler cryptHandler = new CryptHandler(c);
EncryptedEntry encryptedEntry = new EncryptedEntry(path.concat(CryptUtil.CRYPT_EXTENSION), password);
cryptHandler.addEntry(encryptedEntry);
// start the encryption process
ServiceWatcherUtil.runService(c, intent);
}
use of com.amaze.filemanager.database.models.EncryptedEntry in project AmazeFileManager by TeamAmaze.
the class CryptHandler method findEntry.
public EncryptedEntry findEntry(String path) throws GeneralSecurityException, IOException {
String query = "Select * FROM " + TABLE_ENCRYPTED + " WHERE " + COLUMN_ENCRYPTED_PATH + "= \"" + path + "\"";
SQLiteDatabase sqLiteDatabase = getReadableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery(query, null);
EncryptedEntry encryptedEntry = new EncryptedEntry();
if (cursor.moveToFirst()) {
encryptedEntry.setId((cursor.getInt(0)));
encryptedEntry.setPath(cursor.getString(1));
encryptedEntry.setPassword(CryptUtil.decryptPassword(context, cursor.getString(2)));
cursor.close();
} else {
encryptedEntry = null;
}
return encryptedEntry;
}
use of com.amaze.filemanager.database.models.EncryptedEntry in project AmazeFileManager by TeamAmaze.
the class MoveFiles method onPostExecute.
@Override
public void onPostExecute(Boolean movedCorrectly) {
if (movedCorrectly) {
if (mainFrag != null && mainFrag.getCurrentPath().equals(paths.get(0))) {
// mainFrag.updateList();
Intent intent = new Intent(MainActivity.KEY_INTENT_LOAD_LIST);
intent.putExtra(MainActivity.KEY_INTENT_LOAD_LIST_FILE, paths.get(0));
context.sendBroadcast(intent);
}
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
FileUtils.scanFile(f.getPath(), context);
FileUtils.scanFile(paths.get(i) + "/" + f.getName(), context);
}
}
// updating encrypted db entry if any encrypted file was moved
AppConfig.runInBackground(() -> {
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable file : files.get(i)) {
if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
try {
CryptHandler cryptHandler = new CryptHandler(context);
EncryptedEntry oldEntry = cryptHandler.findEntry(file.getPath());
EncryptedEntry newEntry = new EncryptedEntry();
newEntry.setId(oldEntry.getId());
newEntry.setPassword(oldEntry.getPassword());
newEntry.setPath(paths.get(i) + "/" + file.getName());
cryptHandler.updateEntry(oldEntry, newEntry);
} catch (Exception e) {
e.printStackTrace();
// couldn't change the entry, leave it alone
}
}
}
}
});
} else {
for (int i = 0; i < paths.size(); i++) {
Intent intent = new Intent(context, CopyService.class);
intent.putExtra(CopyService.TAG_COPY_SOURCES, files.get(i));
intent.putExtra(CopyService.TAG_COPY_TARGET, paths.get(i));
intent.putExtra(CopyService.TAG_COPY_MOVE, true);
intent.putExtra(CopyService.TAG_COPY_OPEN_MODE, mode.ordinal());
ServiceWatcherUtil.runService(context, intent);
}
}
}
use of com.amaze.filemanager.database.models.EncryptedEntry in project AmazeFileManager by TeamAmaze.
the class MainFragment method findEncryptedEntry.
/**
* Queries database to find entry for the specific path
*
* @param path the path to match with
* @return the entry
*/
private static EncryptedEntry findEncryptedEntry(Context context, String path) throws Exception {
CryptHandler handler = new CryptHandler(context);
EncryptedEntry matchedEntry = null;
// find closest path which matches with database entry
for (EncryptedEntry encryptedEntry : handler.getAllEntries()) {
if (path.contains(encryptedEntry.getPath())) {
if (matchedEntry == null || matchedEntry.getPath().length() < encryptedEntry.getPath().length()) {
matchedEntry = encryptedEntry;
}
}
}
return matchedEntry;
}
Aggregations