From 1886dd1790536e07a0c2e6eac3006e93cb5611e1 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 31 Oct 2014 18:18:09 +0100 Subject: export secret and public keys in separate armored blocks --- .../keychain/operations/ImportExportOperation.java | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'OpenKeychain/src/main/java/org') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java index 9b9c5043d..da532d2dc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java @@ -456,16 +456,17 @@ public class ImportExportOperation extends BaseOperation { // For each public masterKey id while (!cursor.isAfterLast()) { + long keyId = cursor.getLong(0); + ArmoredOutputStream arOutStream = null; + // Create an output stream - ArmoredOutputStream arOutStream = new ArmoredOutputStream(outStream); try { + arOutStream = new ArmoredOutputStream(outStream); String version = PgpHelper.getVersionForHeader(mContext); if (version != null) { arOutStream.setHeader("Version", version); } - long keyId = cursor.getLong(0); - log.add(LogType.MSG_EXPORT_PUBLIC, 1, KeyFormattingUtils.beautifyKeyId(keyId)); { // export public key part @@ -474,19 +475,33 @@ public class ImportExportOperation extends BaseOperation { okPublic += 1; } + } finally { + // make sure this is closed + if (arOutStream != null) { + arOutStream.close(); + } + arOutStream = null; + } + + if (exportSecret && cursor.getInt(3) > 0) { + try { + arOutStream = new ArmoredOutputStream(outStream); + String version = PgpHelper.getVersionForHeader(mContext); + if (version != null) { + arOutStream.setHeader("Version", version); + } // export secret key part - if (exportSecret && cursor.getInt(3) > 0) { log.add(LogType.MSG_EXPORT_SECRET, 2, KeyFormattingUtils.beautifyKeyId(keyId)); byte[] data = cursor.getBlob(2); arOutStream.write(data); okSecret += 1; - } - } finally { - // make sure this is closed - if (arOutStream != null) { - arOutStream.close(); + } finally { + // make sure this is closed + if (arOutStream != null) { + arOutStream.close(); + } } } -- cgit v1.2.3