yakivmospan / scytale

One tool to manage key generation, key storing and encryption on different APIs of Android.
432 stars 45 forks source link

When I call Crypto.decrypt, it gives me a NullPointerException: println needs a message #5

Closed jagan999 closed 7 years ago

jagan999 commented 7 years ago

Can you pl tell me when I get this error? I've verified that the decrypt function is passed a valid string, it is not null

yakivmospan commented 7 years ago

Can you please share the full stack trace here ?

yakivmospan commented 7 years ago

Also you can set an error listener to get more details about exceptions (errors) you got while working with Crypto:

crypto.setErrorListener(new ErrorListener() {
        @Override
        public void onError(Exception e) {
            / / handle error here        
        }
});
jagan999 commented 7 years ago

Full stack trace here...I've stripped out the detailed package name for confidentiality purposes

                                                            Detailed StackTrace
                                                            java.lang.NullPointerException: println needs a message
                                                                at android.util.Log.println_native(Native Method)
                                                                at android.util.Log.e(Log.java:232)
                                                                at com.yakivmospan.scytale.ErrorHandler.onException(ErrorHandler.java:19)
                                                                at com.yakivmospan.scytale.Crypto.decrypt(Crypto.java:178)
                                                                at com.yakivmospan.scytale.Crypto.decrypt(Crypto.java:139)
                                                                at MySQLiteOpenHelper.getEncryptedDBPassword(MySQLiteOpenHelper.java:109)
                                                                at MySQLiteOpenHelper.<init>(MySQLiteOpenHelper.java:48)
                                                                at Tasks.sync(Tasks.java:563)
                                                                at IntentService.onHandleIntent(IntentService.java:84)
                                                                at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                at android.os.Looper.loop(Looper.java:148)
                                                                at android.os.HandlerThread.run(HandlerThread.java:61)
yakivmospan commented 7 years ago

It is crashing on passing an empty exception message to the ErrorHandle. This is an internal error. But you still have some issues on your code cause ErrorHandle is triggered.

Thanks for reporting this. I will fix it and update here ASAP.

jagan999 commented 7 years ago

ok, thanks. I tried to add an error listener but it didn't even get triggered.

yakivmospan commented 7 years ago

Yup cause an issue is rised before, on line number 19, and listener is triggerd after. Anyway as I told you, you got some issues with crypto setup, error handler is triggered only if an exception was thrown during encryption.

https://github.com/yakivmospan/scytale/blob/master/library/src/main/java/com/yakivmospan/scytale/ErrorHandler.java#L19

yakivmospan commented 7 years ago

I've just released new version, please try it :

compile 'com.yakivmospan:scytale:1.0.1'
jagan999 commented 7 years ago

Thanks. Works now. After analysis, I discovered that I was decrypting a string using a different key than that used for encrypt. However, the error thrown was very misleading. Maybe, this is fixed with your new build now. I don't see this error now since I've fixed my code.

yakivmospan commented 7 years ago

Can you please revert changes and try it with new build ? It would be very helpful to analyze if new build can provide your more details about an error an stop crashing. Thanks

jagan999 commented 7 years ago

I want to try and help but I've made too many changes since I reported the issue to roll back and test again. I'll keep you posted if I find any improvement in error logging. BTW, your wrong error never crashed my app, it only threw a confusing error message. Also, your library rocks...great job on that. It simplified my job a whole lot. Thanks for this.

yakivmospan commented 7 years ago

Glad that Scytale helped you and thanks for reporting this issue. Closing it.