tobiasKaminsky 7 жил өмнө
parent
commit
50b56bc09f

+ 2 - 1
src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -313,7 +313,8 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
                 String keyPhrase = stringBuilder.toString();
                 String keyPhrase = stringBuilder.toString();
 
 
                 String privateKeyString = EncryptionUtils.encodeBytesToBase64String(privateKey.getEncoded());
                 String privateKeyString = EncryptionUtils.encodeBytesToBase64String(privateKey.getEncoded());
-                String encryptedPrivateKey = EncryptionUtils.encryptPrivateKey(privateKeyString, keyPhrase);
+                String privatePemKeyString = EncryptionUtils.privateKeyToPEM(privateKey);
+                String encryptedPrivateKey = EncryptionUtils.encryptPrivateKey(privatePemKeyString, keyPhrase);
 
 
                 // upload encryptedPrivateKey
                 // upload encryptedPrivateKey
                 StorePrivateKeyOperation storePrivateKeyOperation = new StorePrivateKeyOperation(encryptedPrivateKey);
                 StorePrivateKeyOperation storePrivateKeyOperation = new StorePrivateKeyOperation(encryptedPrivateKey);

+ 11 - 1
src/main/java/com/owncloud/android/utils/EncryptionUtils.java

@@ -541,7 +541,17 @@ public class EncryptionUtils {
         byte[] bytes = decodeStringToBase64Bytes(realPrivateKey);
         byte[] bytes = decodeStringToBase64Bytes(realPrivateKey);
         byte[] decrypted = cipher.doFinal(bytes);
         byte[] decrypted = cipher.doFinal(bytes);
 
 
-        return decodeBase64BytesToString(decrypted);
+        String pemKey = decodeBase64BytesToString(decrypted);
+
+        return pemKey.replaceAll("\n", "").replace("-----BEGIN PRIVATE KEY-----", "")
+                .replace("-----END PRIVATE KEY-----", "");
+    }
+
+    public static String privateKeyToPEM(PrivateKey privateKey) throws IOException {
+        String privateKeyString = encodeBytesToBase64String(privateKey.getEncoded());
+
+        return "-----BEGIN PRIVATE KEY-----\n" + privateKeyString.replaceAll("(.{65})", "$1\n")
+                + "\n-----END PRIVATE KEY-----";
     }
     }
 
 
     /*
     /*