· 7 years ago · Jul 02, 2018, 08:48 AM
1public Boolean validateKeys(Boolean checkFingerPrintChanges) {
2 if (checkFingerPrintChanges && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
3 Cipher cipher;
4 try {
5 cipher = Cipher.getInstance(
6 KeyProperties.KEY_ALGORITHM_AES + "/"
7 + KeyProperties.BLOCK_MODE_CBC + "/"
8 + KeyProperties.ENCRYPTION_PADDING_PKCS7);
9 } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
10 return false;
11 }
12
13 if (keyStore == null) {
14 return false;
15 }
16 try {
17 SecretKey key = (SecretKey) keyStore.getKey(CHECK_KEY_NAME, null);
18 cipher.init(Cipher.ENCRYPT_MODE, key);
19 return true;
20 } catch (Exception e) {
21 if (e instanceof KeyPermanentlyInvalidatedException) {
22 deleteAllEntries(true);
23 }
24 return false;
25 }
26 }
27 return true;
28}