With this code:
Dim k2 As KeyPairGenerator
k2.Initialize("RSA",2048)
k2.PrivateKeyFromBytes(ByteFromPrivKey)
Dim sign As Signature
sign.Initialise("SHA256withECDSA",sign.SIGNATURE_SIGN,k2.PrivateKey)
sign.Update(bfiletemp)
I have this error at line k2.PrivateKeyFromBytes(ByteFromPrivKey):
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_firma (B4A line: 155)
k2.PrivateKeyFromBytes(ByteFromPrivKey)
java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
at com.android.org.conscrypt.OpenSSLKey.getPrivateKey(OpenSSLKey.java:180)
at com.android.org.conscrypt.OpenSSLRSAKeyFactory.engineGeneratePrivate(OpenSSLRSAKeyFactory.java:64)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:187)
at anywheresoftware.b4a.agraham.encryption.CipherWrapper$KeyPairGeneratorWrapper.PrivateKeyFromBytes(CipherWrapper.java:457)
at b4a.example.main._firma(main.java:754)
at b4a.example.main._activity_create(main.java:370)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:19)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
at com.android.org.conscrypt.NativeCrypto.d2i_PKCS8_PRIV_KEY_INFO(Native Method)
at com.android.org.conscrypt.OpenSSLKey.getPrivateKey(OpenSSLKey.java:178)
... 19 more