Simplify the exception catching in KeyStoreHelper
This commit is contained in:
parent
c0d05c8e2c
commit
1e21c36ecc
1 changed files with 4 additions and 13 deletions
|
@ -100,26 +100,17 @@ public class KeyStoreHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SecretKey loadEncryptionKeyFromKeyStore(Context context, boolean failSilent) {
|
public static SecretKey loadEncryptionKeyFromKeyStore(Context context, boolean failSilent) {
|
||||||
KeyPair pair = null;
|
SecretKey encKey = null;
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (GeneralSecurityException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (! failSilent)
|
if (! failSilent)
|
||||||
UIHelper.showGenericDialog(context, R.string.dialog_title_keystore_error, R.string.dialog_msg_keystore_error);
|
UIHelper.showGenericDialog(context, R.string.dialog_title_keystore_error, R.string.dialog_msg_keystore_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pair != null) {
|
return encKey;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue