android.security.keystore.KeyPermanentlyInvalidatedException Java Examples
The following examples show how to use
android.security.keystore.KeyPermanentlyInvalidatedException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CryptoObjectHelper.java From AndroidFingerPrintDemo with Apache License 2.0 | 7 votes |
Cipher createCipher(boolean retry) throws Exception { Key key = GetKey(); Cipher cipher = Cipher.getInstance(TRANSFORMATION); try { cipher.init(Cipher.ENCRYPT_MODE | Cipher.DECRYPT_MODE, key); } catch(KeyPermanentlyInvalidatedException e) { _keystore.deleteEntry(KEY_NAME); if(retry) { createCipher(false); } else { throw new Exception("Could not create the cipher for fingerprint authentication.", e); } } return cipher; }
Example #2
Source File: CryptoObjectHelper.java From LLApp with Apache License 2.0 | 7 votes |
@RequiresApi(api = Build.VERSION_CODES.M) public Cipher createCipher(boolean retry) throws Exception { Key key = GetKey(); Cipher cipher = Cipher.getInstance(TRANSFORMATION); try { cipher.init(Cipher.ENCRYPT_MODE | Cipher.DECRYPT_MODE, key); } catch(KeyPermanentlyInvalidatedException e) { _keystore.deleteEntry(KEY_NAME); if(retry) { createCipher(false); } else { throw new Exception("Could not create the cipher for fingerprint authentication.", e); } } return cipher; }
Example #3
Source File: CipherProvider.java From RxFingerprint with Apache License 2.0 | 7 votes |
@TargetApi(Build.VERSION_CODES.M) Exception mapCipherFinalOperationException(Exception e) { boolean shouldThrowKeyPermanentlyInvalidatedException = invalidatedByBiometricEnrollment && Build.VERSION.SDK_INT == 26 /*Build.VERSION_CODES.O*/ && e instanceof IllegalBlockSizeException; if (shouldThrowKeyPermanentlyInvalidatedException) { Logger.warn("Removing invalidated key."); try { removeKey(keyName); } catch (Exception exception) { Logger.error("Removing invalidated key failed.", exception); } return new KeyPermanentlyInvalidatedException(); } return e; }
Example #4
Source File: KeychainAuthenticatedActivity.java From Android-Vault with Apache License 2.0 | 5 votes |
@Override protected boolean handleRuntimeException(SharedPreferenceVault sharedPreferenceVault, int requestCode, Throwable throwable) { boolean handled = false; if (throwable instanceof UserNotAuthenticatedException) { Log.w(TAG, "User authentication expired"); showAuthenticationScreen(requestCode); handled = true; } else if (throwable instanceof KeyPermanentlyInvalidatedException) { Log.w(TAG, "User changed unlock code and permanently invalidated the key"); sharedPreferenceVault.rekeyStorage(null); completeOperationForRequestCode(requestCode); handled = true; } return handled; }
Example #5
Source File: CipherProvider.java From RxFingerprint with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.M) Cipher getCipherForEncryption() throws IOException, GeneralSecurityException { try { return cipherForEncryption(); } catch (KeyPermanentlyInvalidatedException e) { Logger.warn("Renewing invalidated key."); removeKey(keyName); return cipherForEncryption(); } }
Example #6
Source File: RxFingerprintTest.java From RxFingerprint with Apache License 2.0 | 4 votes |
@Test public void testKeyInvalidatedException() throws Exception { Throwable throwable = new KeyPermanentlyInvalidatedException(); assertTrue("Should result to true", RxFingerprint.keyInvalidated(throwable)); }
Example #7
Source File: RxFingerprint.java From RxFingerprint with Apache License 2.0 | 2 votes |
/** * Checks if the provided {@link Throwable} is of type {@link KeyPermanentlyInvalidatedException} * <p/> * This would mean that the user has disabled the lock screen on his device or changed the * fingerprints stored on the device for authentication. * <p/> * If the user does this all keys encrypted by {@link RxFingerprint} become permanently * invalidated by the Android system. To continue using encryption you have to ask the user to * encrypt the original data again. The old data is not accessible anymore. * * @param throwable Throwable received in {@link org.reactivestreams.Subscriber#onError(Throwable)} from * an {@link RxFingerprint} encryption method * @return {@code true} if the requested key was permanently invalidated and cannot be used * anymore */ public static boolean keyInvalidated(Throwable throwable) { return throwable instanceof KeyPermanentlyInvalidatedException; }