Android Question Create .jks from pfx and cer certificates

nesam

Member
Licensed User
Longtime User
Using the instruction from https://www.b4x.com/android/forum/t...tils2-sslcontext-kickstart.132549/post-839195
I created an .jks file but when I try to load certificates I get an error.

B4X:
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 53 (B4XMainPage)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1055)
    at b4a.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1061)
    at b4a.example.b4xpagesmanager._showpage(b4xpagesmanager.java:418)
    at b4a.example.b4xpagesmanager._addpage(b4xpagesmanager.java:246)
    at b4a.example.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:260)
    at b4a.example.b4xpagesmanager._initialize(b4xpagesmanager.java:166)
    at b4a.example.main._activity_create(main.java:417)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:250)
    at android.app.ActivityThread.main(ActivityThread.java:7851)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
    at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
    ... 24 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
    ... 25 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4a.example.b4xmainpage._setsslfactory(b4xmainpage.java:191)
    at b4a.example.b4xmainpage$ResumableSub_B4XPage_Created.resume(b4xmainpage.java:80)
    at b4a.example.b4xmainpage._b4xpage_created(b4xmainpage.java:46)
    ... 27 more
Caused by: java.io.IOException: PKCS12 key store mac invalid - wrong password or corrupted file.
    at com.android.org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(PKCS12KeyStoreSpi.java:844)
    at java.security.KeyStore.load(KeyStore.java:1484)
    ... 32 more
** Activity (main) Resume **

Is the problem in: Caused by: java.io.IOException: PKCS12 key store mac invalid - wrong password or corrupted file ?
 

nesam

Member
Licensed User
Longtime User
Looks like the password is incorrect. Are you able to open it with kse?
Yes, it normally reads and adds CA1 and RCA.

I tried a lot of versions. There is another error, maybe the java version is different
Caused by: java.io.IOException: exception unwrapping private key - java.security.NoSuchAlgorithmException: 1.2.840.113549.1.5.12 SecretKeyFactory not available


B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 53 (B4XMainPage)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4a.example.b4xmainpage._setsslfactory(b4xmainpage.java:191)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at b4a.example.b4xmainpage._b4xpage_created(b4xmainpage.java:44)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
    at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1055)
    at b4a.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1061)
    at b4a.example.b4xpagesmanager._showpage(b4xpagesmanager.java:418)
    at b4a.example.b4xpagesmanager._addpage(b4xpagesmanager.java:246)
    at b4a.example.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:260)
    at b4a.example.b4xpagesmanager._initialize(b4xpagesmanager.java:166)
    at b4a.example.main._activity_create(main.java:417)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:250)
    at android.app.ActivityThread.main(ActivityThread.java:7851)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Caused by: java.io.IOException: exception unwrapping private key - java.security.NoSuchAlgorithmException: 1.2.840.113549.1.5.12 SecretKeyFactory not available
    at com.android.org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.unwrapKey(PKCS12KeyStoreSpi.java:652)
    at com.android.org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(PKCS12KeyStoreSpi.java:891)
    at java.security.KeyStore.load(KeyStore.java:1484)
    ... 38 more
 
Upvote 0

nesam

Member
Licensed User
Longtime User
I made the conversion with your files and it worked. You should get it working too. I've used keytool from Java 11.
I also tried java 8 and 11.
I use: keytool -importkeystore -srckeystore 1.pfx -srcstoretype pkcs12 -destkeystore c: \users\public\clientcert.jks -deststoretype pkcs12
enter destpass and srcpass. Open KSE, import Trusted certificate CA1 and RCA. Save.
 
Last edited:
Upvote 0

nesam

Member
Licensed User
Longtime User
I cannot open the keystore file with kse and the password you supplied. You should have tried it yourself...

pass "123456"

S1.jpg
 
Upvote 0

nesam

Member
Licensed User
Longtime User
There are two keystore files in the Files folder (why?).
I've now tried to open the second one. It also doesn't work.
clientcert.jks you created, clientcert100.jks is me. Everything works with yours, not with mine.
My KSE is 5.4.4 version
 
Last edited:
Upvote 0
Top