tntkhang / realm-encryption-helper

Library for generating a key to encrypt/decypt Realm DB
23 stars 5 forks source link

NullPointer Exception #4

Open genie137 opened 6 years ago

genie137 commented 6 years ago

I just got a nullpointerexception while getting the key. It seems to make the key go all 0`s.... Any hints?

java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] java.lang.String.getBytes()' on a null object reference
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at android.util.Base64.decode(Base64.java:118)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at com.github.tntkhang.realmencryptionhelper.RealmEncryptionHelper.getSecretKey(RealmEncryptionHelper.java:120)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at com.github.tntkhang.realmencryptionhelper.RealmEncryptionHelper.getEncryptKey(RealmEncryptionHelper.java:107)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at <PACKAGE>datamanagement.Connector.openSyncedRealm(Connector.java:66)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at <PACKAGE>datamanagement.Connector.access$100(Connector.java:14)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at <PACKAGE>datamanagement.Connector$1.onSuccess(Connector.java:36)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at <PACKAGE>datamanagement.Connector$1.onSuccess(Connector.java:30)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at io.realm.SyncUser$Request$3.run(SyncUser.java:695)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at android.os.Handler.handleCallback(Handler.java:751)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at android.os.Looper.loop(Looper.java:154)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6692)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
03-21 11:16:50.837 562-562/<PACKAGE> W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
03-21 11:16:50.837 562-562/<PACKAGE> I/tntkhang: getSecretKey string: null
03-21 11:16:50.837 562-562/<PACKAGE> I/tntkhang: getSecretKey key: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
03-21 11:16:50.837 562-562/<PACKAGE> I/tntkhang: encryptedKey: 64 -- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
genie137 commented 6 years ago

Hmm, when i delete the data and cache of the app. it generates a non-0 key. but still now throws another error:

03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.security.cert.Certificate java.security.KeyStore$PrivateKeyEntry.getCertificate()' on a null object reference
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at com.github.tntkhang.realmencryptionhelper.RealmEncryptionHelper.rsaEncrypt(RealmEncryptionHelper.java:154)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at com.github.tntkhang.realmencryptionhelper.RealmEncryptionHelper.generate64BitSecretKey(RealmEncryptionHelper.java:139)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at com.github.tntkhang.realmencryptionhelper.RealmEncryptionHelper.getEncryptKey(RealmEncryptionHelper.java:104)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at <PACKAGE>.datamanagement.Connector.openSyncedRealm(Connector.java:66)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at <PACKAGE>.datamanagement.Connector.access$100(Connector.java:14)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at <PACKAGE>.datamanagement.Connector$1.onSuccess(Connector.java:36)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at <PACKAGE>.datamanagement.Connector$1.onSuccess(Connector.java:30)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at io.realm.SyncUser$Request$3.run(SyncUser.java:695)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at android.os.Handler.handleCallback(Handler.java:751)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at android.os.Looper.loop(Looper.java:154)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6692)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
03-21 11:24:58.927 3756-3756/<PACKAGE>. W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
03-21 11:24:58.928 3756-3756/<PACKAGE>. I/tntkhang: generate64BitSecretKey key: [-45, -28, -97, 40, 38, 22, -28, 103, -45, 97, -60, 57, -84, -77, -36, 123, -37, 113, -5, -78, -5, -36, -23, 52, -15, -60, -11, -35, 85, 37, 5, 44, -88, 6, -40, -42, -17, -15, 5, 110, -2, -67, -98, 127, -107, -92, -86, 120, -97, 29, -103, -27, -69, 50, -119, 48, 55, -7, 33, -110, -12, -45, 126, 34]
03-21 11:24:58.928 3756-3756/<PACKAGE>. I/tntkhang: encryptedKey: 64 -- [-45, -28, -97, 40, 38, 22, -28, 103, -45, 97, -60, 57, -84, -77, -36, 123, -37, 113, -5, -78, -5, -36, -23, 52, -15, -60, -11, -35, 85, 37, 5, 44, -88, 6, -40, -42, -17, -15, 5, 110, -2, -67, -98, 127, -107, -92, -86, 120, -97, 29, -103, -27, -69, 50, -119, 48, 55, -7, 33, -110, -12, -45, 126, 34]
tntkhang commented 6 years ago

I will try to reproduce and investigate this bug. Thanks

genie137 commented 6 years ago

Do you have an ETA on the fix?

tntkhang commented 6 years ago

Still not found the solution :(