Skip to content

Commit d5f5d0a

Browse files
committed
Fixed keystore reset each boot
1 parent 7d42e23 commit d5f5d0a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public class RNSensitiveInfoModule extends ReactContextBaseJavaModule {
4949
KeyProperties.BLOCK_MODE_CBC + "/" +
5050
KeyProperties.ENCRYPTION_PADDING_PKCS7;
5151

52+
private static final String AES_GCM = "AES/GCM/NoPadding";
53+
private static final String AES_ECB = "AES/ECB/PKCS7Padding";
54+
private static final String DELIMITER = "]";
5255
private static final byte[] FIXED_IV = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1};
5356
private static final String KEY_ALIAS = "MySharedPreferenceKeyAlias";
5457
private static final String KEY_ALIAS_AES = "MyAesKeyAlias";
55-
private static final String DELIMITER = "]";
56-
private static final String AES_GCM = "AES/GCM/NoPadding";
57-
private static final String AES_ECB = "AES/ECB/PKCS7Padding";
5858

5959
private FingerprintManager mFingerprintManager;
6060
private KeyStore mKeyStore;
@@ -237,7 +237,7 @@ private void initKeyStore() {
237237
mKeyStore = KeyStore.getInstance(ANDROID_KEYSTORE_PROVIDER);
238238
mKeyStore.load(null);
239239

240-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
240+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !mKeyStore.containsAlias(KEY_ALIAS)) {
241241
KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEYSTORE_PROVIDER);
242242
keyGenerator.init(
243243
new KeyGenParameterSpec.Builder(KEY_ALIAS,
@@ -248,6 +248,7 @@ private void initKeyStore() {
248248
.build());
249249
keyGenerator.generateKey();
250250
}
251+
251252
// Check if a generated key exists under the KEY_ALIAS_AES .
252253
if (!mKeyStore.containsAlias(KEY_ALIAS_AES)) {
253254
prepareKey();

0 commit comments

Comments
 (0)