1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

Add method to export an encrypted settings file

This commit is contained in:
cketti 2011-03-30 05:31:48 +02:00
parent 6258118ed6
commit 8850915987

View File

@ -10,6 +10,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.crypto.CipherOutputStream;
import org.xmlpull.v1.XmlSerializer;
import android.content.Context;
@ -57,7 +58,13 @@ public class StorageExporter {
File file = Utility.createUniqueFile(dir, EXPORT_FILENAME);
String fileName = file.getAbsolutePath();
os = new FileOutputStream(fileName);
if (encryptionKey == null) {
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.
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,
Set<String> accountUuids) throws StorageImportExportException {