Simplify the exception catching in KeyStoreHelper

This commit is contained in:
Jakob Nixdorf 2018-01-10 07:12:02 +01:00
parent c0d05c8e2c
commit 1e21c36ecc
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC

View file

@ -100,26 +100,17 @@ public class KeyStoreHelper {
}
public static SecretKey loadEncryptionKeyFromKeyStore(Context context, boolean failSilent) {
KeyPair pair = null;
SecretKey encKey = null;
try {
pair = KeyStoreHelper.loadOrGenerateAsymmetricKeyPair(context, Constants.KEYSTORE_ALIAS_WRAPPING);
KeyPair pair = KeyStoreHelper.loadOrGenerateAsymmetricKeyPair(context, Constants.KEYSTORE_ALIAS_WRAPPING);
encKey = EncryptionHelper.loadOrGenerateWrappedKey(new File(context.getFilesDir() + "/" + Constants.FILENAME_ENCRYPTED_KEY), pair);
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
if (! failSilent)
UIHelper.showGenericDialog(context, R.string.dialog_title_keystore_error, R.string.dialog_msg_keystore_error);
}
if (pair != null) {
try {
return EncryptionHelper.loadOrGenerateWrappedKey(new File(context.getFilesDir() + "/" + Constants.FILENAME_ENCRYPTED_KEY), pair);
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
if (! failSilent)
UIHelper.showGenericDialog(context, R.string.dialog_title_keystore_error, R.string.dialog_msg_keystore_error);
}
}
return null;
return encKey;
}
}