mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Add method to export an encrypted settings file
This commit is contained in:
parent
6258118ed6
commit
8850915987
@ -10,6 +10,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import javax.crypto.CipherOutputStream;
|
||||||
import org.xmlpull.v1.XmlSerializer;
|
import org.xmlpull.v1.XmlSerializer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -57,7 +58,13 @@ public class StorageExporter {
|
|||||||
File file = Utility.createUniqueFile(dir, EXPORT_FILENAME);
|
File file = Utility.createUniqueFile(dir, EXPORT_FILENAME);
|
||||||
String fileName = file.getAbsolutePath();
|
String fileName = file.getAbsolutePath();
|
||||||
os = new FileOutputStream(fileName);
|
os = new FileOutputStream(fileName);
|
||||||
|
|
||||||
|
if (encryptionKey == null) {
|
||||||
exportPreferences(context, os, includeGlobals, accountUuids);
|
exportPreferences(context, os, includeGlobals, accountUuids);
|
||||||
|
} else {
|
||||||
|
exportPreferencesEncrypted(context, os, includeGlobals, accountUuids,
|
||||||
|
encryptionKey);
|
||||||
|
}
|
||||||
|
|
||||||
// If all went well, we return the name of the file just written.
|
// If all went well, we return the name of the file just written.
|
||||||
return fileName;
|
return fileName;
|
||||||
@ -72,6 +79,19 @@ public class StorageExporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void exportPreferencesEncrypted(Context context, OutputStream os, boolean includeGlobals,
|
||||||
|
Set<String> accountUuids, String encryptionKey) throws StorageImportExportException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
K9Krypto k = new K9Krypto(encryptionKey, K9Krypto.MODE.ENCRYPT);
|
||||||
|
CipherOutputStream cos = new CipherOutputStream(os, k.mCipher);
|
||||||
|
|
||||||
|
exportPreferences(context, cos, includeGlobals, accountUuids);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new StorageImportExportException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void exportPreferences(Context context, OutputStream os, boolean includeGlobals,
|
public static void exportPreferences(Context context, OutputStream os, boolean includeGlobals,
|
||||||
Set<String> accountUuids) throws StorageImportExportException {
|
Set<String> accountUuids) throws StorageImportExportException {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user