I have a routine, in which the device request's to the server for a keypair, the server returns the public key to be stored on the device. The public key is recieved via httpjob and stored in a local database.
The last line gives me:
What goes wrong? is it the UTF conversion?
Thanks in advance
Felipe Brito
B4X:
'x.ReadMap is a public function to read a record from a parameters table in the database.
Dim pubkey(0) As Byte = Bconv.StringToBytes(x.ReadMap("publicKey"), "UTF8")
Dim enc As Cipher
enc.Initialize("RSA")
Dim kpg As KeyPairGenerator
kpg.Initialize("RSA", 512)
kpg.PublicKeyFromBytes(pubkey)
The last line gives me:
B4X:
java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
at org.apache.harmony.xnet.provider.jsse.OpenSSLRSAKeyFactory.engineGeneratePublic(OpenSSLRSAKeyFactory.java:52)
at java.security.KeyFactory.generatePublic(KeyFactory.java:171)
at anywheresoftware.b4a.agraham.encryption.CipherWrapper$KeyPairGeneratorWrapper.PublicKeyFromBytes(CipherWrapper.java:446)
at com.autorizalo.android.main._activity_create(main.java:534)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at com.autorizalo.android.main.afterFirstLayout(main.java:89)
at com.autorizalo.android.main.access$100(main.java:16)
at com.autorizalo.android.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.d2i_PUBKEY(Native Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLRSAKeyFactory.engineGeneratePublic(OpenSSLRSAKeyFactory.java:48)
What goes wrong? is it the UTF conversion?
Thanks in advance
Felipe Brito