· 9 years ago · Oct 30, 2016, 02:20 AM
1try {
2 KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
3 keyStore.load(null);
4
5 SecretKey secretKey =
6 (SecretKey) keyStore.getKey(SecurityConstants.KEY_AES, null);
7 Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
8
9 // The next line may throw a UserNotAuthenticatedException and
10 // we need to prompt the user to authenticate again
11 cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));
12 byte[] decryptedBytes = cipher.doFinal(cipherBytes);
13
14} catch (UserNotAuthenticatedException e) {
15 // User is not authenticated, let's authenticate with
16 // device credentials!
17 showAuthenticationScreen();
18 return;
19} catch { … }