From 5a9a0260912df7f5b3708cd90b7273a7ca1ef632 Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Thu, 14 May 2020 12:09:46 +0200 Subject: [PATCH] Small fix to generatePassphrase to avoid overwriting the key. --- .../privacyfriendlyfoodtracker/helpers/KeyGenHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/org/secuso/privacyfriendlyfoodtracker/helpers/KeyGenHelper.java b/app/src/main/java/org/secuso/privacyfriendlyfoodtracker/helpers/KeyGenHelper.java index 884ae33..cff27d9 100644 --- a/app/src/main/java/org/secuso/privacyfriendlyfoodtracker/helpers/KeyGenHelper.java +++ b/app/src/main/java/org/secuso/privacyfriendlyfoodtracker/helpers/KeyGenHelper.java @@ -112,7 +112,10 @@ public static void generateKey(Context context) throws Exception { */ public static void generatePassphrase(Context context) throws Exception { SharedPreferences pref = context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); + String enryptedKeyB64 = pref.getString(ENCRYPTED_KEY, null); + if(enryptedKeyB64 != null) return; + byte[] encryptedKey = rsaEncrypt(generateKeyPassphrase()); enryptedKeyB64 = Base64.encodeToString(encryptedKey, Base64.DEFAULT); SharedPreferences.Editor edit = pref.edit();