mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
use pem for private key
This commit is contained in:
parent
c534d603c7
commit
50b56bc09f
2 changed files with 13 additions and 2 deletions
|
@ -313,7 +313,8 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|||
String keyPhrase = stringBuilder.toString();
|
||||
|
||||
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
|
||||
StorePrivateKeyOperation storePrivateKeyOperation = new StorePrivateKeyOperation(encryptedPrivateKey);
|
||||
|
|
|
@ -541,7 +541,17 @@ public class EncryptionUtils {
|
|||
byte[] bytes = decodeStringToBase64Bytes(realPrivateKey);
|
||||
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-----";
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue