Skip to content

Commit db4e1e6

Browse files
authored
Merge pull request #217 from maggialejandro/fix-unrecoverable-key-exception
fix(android): handle UnrecoverableKeyException
2 parents fc62b6f + 79c8197 commit db4e1e6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

android/src/main/java/br/com/classapp/RNSensitiveInfo/RNSensitiveInfoModule.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.facebook.react.modules.core.DeviceEventManagerModule;
3232

3333
import java.security.KeyStore;
34+
import java.security.UnrecoverableKeyException;
3435
import java.util.HashMap;
3536
import java.util.Map;
3637
import java.util.concurrent.Executor;
@@ -295,6 +296,7 @@ private void initKeyStore() {
295296
prepareKey();
296297
}
297298
} catch (Exception e) {
299+
//
298300
}
299301
}
300302

@@ -337,7 +339,6 @@ private void putExtraWithAES(final String key, final String value, final SharedP
337339
cipher = Cipher.getInstance(AES_DEFAULT_TRANSFORMATION);
338340
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
339341

340-
341342
// Retrieve information about the SecretKey from the KeyStore.
342343
SecretKeyFactory factory = SecretKeyFactory.getInstance(
343344
secretKey.getAlgorithm(), ANDROID_KEYSTORE_PROVIDER);
@@ -404,6 +405,7 @@ public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult re
404405
}
405406
return;
406407
}
408+
407409
byte[] encryptedBytes = cipher.doFinal(value.getBytes());
408410

409411
// Encode the initialization vector (IV) and encryptedBytes to Base64.
@@ -414,7 +416,7 @@ public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult re
414416

415417
putExtra(key, result, mSharedPreferences);
416418
pm.resolve(value);
417-
} catch (InvalidKeyException e) {
419+
} catch (InvalidKeyException | UnrecoverableKeyException e) {
418420
try {
419421
mKeyStore.deleteEntry(KEY_ALIAS_AES);
420422
prepareKey();
@@ -522,7 +524,7 @@ public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult re
522524
}
523525
byte[] decryptedBytes = cipher.doFinal(cipherBytes);
524526
pm.resolve(new String(decryptedBytes));
525-
} catch (InvalidKeyException e) {
527+
} catch (InvalidKeyException | UnrecoverableKeyException e) {
526528
try {
527529
mKeyStore.deleteEntry(KEY_ALIAS_AES);
528530
prepareKey();

0 commit comments

Comments
 (0)