Skip to content

Commit 2badfc4

Browse files
authored
Merge pull request #74 from igorrfc/keystore
Fixing the "java.lang.NullPointerException" at RNSensitiveInfo module
2 parents 55856ba + 64da90b commit 2badfc4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public RNSensitiveInfoModule(ReactApplicationContext reactContext) {
5555
try {
5656
initKeyStore(reactContext);
5757
} catch (Exception e) {
58-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
58+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
5959
}
6060
}
6161

@@ -74,7 +74,7 @@ public void getItem(String key, ReadableMap options, Promise pm) {
7474
try {
7575
value = decrypt(value);
7676
} catch (Exception e) {
77-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
77+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
7878
}
7979
}
8080

@@ -90,7 +90,7 @@ public void setItem(String key, String value, ReadableMap options, Promise pm) {
9090
putExtra(key, value, prefs(name));
9191
pm.resolve(null);
9292
} catch (Exception e) {
93-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
93+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
9494
pm.reject(e);
9595
}
9696
}
@@ -122,7 +122,7 @@ public void getAllItems(ReadableMap options, Promise pm) {
122122
try {
123123
value = decrypt(value);
124124
} catch (Exception e) {
125-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
125+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
126126
}
127127
resultData.putString(entry.getKey(), value);
128128
}
@@ -259,7 +259,13 @@ public String encrypt(String input) throws Exception {
259259

260260

261261
public String decrypt(String encrypted) throws Exception {
262+
if (encrypted == null) {
263+
Exception cause = new RuntimeException("Invalid argument at decrypt function");
264+
throw new RuntimeException("encrypted argument can't be null", cause);
265+
}
266+
262267
Cipher c;
268+
263269
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
264270
c = Cipher.getInstance(AES_GCM);
265271
c.init(Cipher.DECRYPT_MODE, secretKey, new GCMParameterSpec(128, FIXED_IV));

0 commit comments

Comments
 (0)