B4J Question Error When Attempting To kvs.GetEncrypted(...) With Wrong Password

cklester

Well-Known Member
Licensed User
Not sure what this error means, nor how to resolve it. Does anybody know how to fix this?

I just installed the new B4J, but I'm not 100% sure this error coincides with the upgrade... but it seems to be. This was definitely working earlier today...

B4X:
Error occurred on line: 111 (KeyValueStore)
org.bouncycastle.crypto.InvalidCipherTextException: pad block corrupted
    at org.bouncycastle.crypto.paddings.PKCS7Padding.padCount(Unknown Source)
    at org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.doFinal(Unknown Source)
    at anywheresoftware.b4x.object.B4XEncryption.Decrypt(B4XEncryption.java:73)
    at b4j.example.keyvaluestore._getencrypted(keyvaluestore.java:63)
    at b4j.example.page_signin._bttn_login_click(page_signin.java:122)
    at b4j.example.page_signin._txt_loginpassword_action(page_signin.java:197)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
 

cklester

Well-Known Member
Licensed User
OK, it's crashing when I attempt to use the wrong password in GetEncrypted().

I'm pretty sure it was not crashing prior to my upgrading of B4J... And I'm not sure it should crash just because I use the wrong password.
 
Upvote 0

cklester

Well-Known Member
Licensed User
I think you are talking about KeyValueStore2 which has PutEncrypted and GetEncrypted methods. Now among the internal libraries there is the KeyValueStore library (B4Xlib) which does not have these methods.

Yes, it's a KVS.
 
Upvote 0

cklester

Well-Known Member
Licensed User
It only crashes when I try the wrong password, not when I use the correct one.
 

Attachments

  • test_kvs_encrypted.zip
    936 bytes · Views: 277
Upvote 0

cklester

Well-Known Member
Licensed User
It's true but even with older B4J versions.

I swear this was working fine before...

B4X:
    Dim ud As Map = App.userData.GetEncrypted("user_data",pw)
    If ud.IsInitialized Then 'password worked

I think it should return null if it fails. @Erel , can we get this to pass back a null instead?

@LucaMs I will try that Try-Catch block in the meantime. Thanks!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It always throws an error when the password is wrong.

This is the code from the example project:
B4X:
    'encrypt the list
    Starter.kvs.PutEncrypted( "encrypted list", list1, "topsecret")
    Try 
        Log("An error message will be printed in debug mode...")
        list2 = Starter.kvs.GetEncrypted("encrypted list", "wrong password")
    Catch
        Log("Wrong password!")
    End Try
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Upvote 0
Top