Search in sources :

Example 1 with EncryptedEntry

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;
}
Also used : CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry)

Example 2 with EncryptedEntry

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);
}
Also used : CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry)

Example 3 with EncryptedEntry

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;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry) Cursor(android.database.Cursor)

Example 4 with 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);
        }
    }
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry) Intent(android.content.Intent) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) SmbException(jcifs.smb.SmbException) MalformedURLException(java.net.MalformedURLException)

Example 5 with EncryptedEntry

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;
}
Also used : CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry)

Aggregations

EncryptedEntry (com.amaze.filemanager.database.models.EncryptedEntry)8 CryptHandler (com.amaze.filemanager.database.CryptHandler)5 Intent (android.content.Intent)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 SharedPreferences (android.content.SharedPreferences)1 Toast (android.widget.Toast)1 ShellNotRunningException (com.amaze.filemanager.exceptions.ShellNotRunningException)1 HybridFile (com.amaze.filemanager.filesystem.HybridFile)1 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)1 Operations (com.amaze.filemanager.filesystem.Operations)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 SmbException (jcifs.smb.SmbException)1