use pem for private key

This commit is contained in:
tobiasKaminsky 2017-10-27 09:21:39 +02:00
parent c534d603c7
commit 50b56bc09f
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 13 additions and 2 deletions

View file

@ -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);

View file

@ -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-----";
}
/*