Add method to export an encrypted settings file
This commit is contained in:
parent
6258118ed6
commit
8850915987
1 changed files with 21 additions and 1 deletions
|
@ -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);
|
||||
exportPreferences(context, os, includeGlobals, accountUuids);
|
||||
|
||||
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 {
|
||||
|
||||
|
|
Loading…
Reference in a new issue