i like to use JB4XEncryption liabraries to encrypt the string from B4J application and store in sqlite database, then i add the database to B4A application to decrypt the string. here is my B4J code:
and below is B4A code:
here is error msg
please help me.
B4X:
Dim s_server_data_name, s_server_host, s_server_user, s_server_password, s_server_port As String
s_server_data_name = "staff_phone_data_record"
s_server_host="xx.xx.xx.xx"
s_server_user="user"
s_server_password="password"
s_server_port="4000"
Dim b_server_data_name() As Byte
Dim b_server_host() As Byte
Dim b_server_user() As Byte
Dim b_server_password() As Byte
Dim b_server_port() As Byte
Dim crypt_s_server_data_name As String = ""
Dim crypt_s_server_host As String = ""
Dim crypt_s_server_user As String = ""
Dim crypt_s_server_password As String = ""
Dim crypt_s_server_port As String = ""
b_server_data_name = Encrypt(s_server_data_name)
crypt_s_server_data_name = BytesToString(b_server_data_name, 0, b_server_data_name.Length, "UTF8")
b_server_host = Encrypt(s_server_host)
crypt_s_server_host = BytesToString(b_server_host, 0, b_server_host.Length, "UTF8")
b_server_user = Encrypt(s_server_user)
crypt_s_server_user = BytesToString(b_server_user, 0, b_server_user.Length, "UTF8")
b_server_password = Encrypt(s_server_password)
crypt_s_server_password = BytesToString(b_server_password, 0, b_server_password.Length, "UTF8")
b_server_port = Encrypt(s_server_port)
crypt_s_server_port = BytesToString(b_server_port, 0, b_server_port.Length, "UTF8")
Dim Query As String = "INSERT INTO tbl_server_detail VALUES (NULL,?,?,?,?,?)"
sql1.ExecNonQuery2(Query,Array As String(crypt_s_server_data_name,crypt_s_server_host,crypt_s_server_user,crypt_s_server_password,crypt_s_server_port))
End Sub
Sub btn_generate_MouseClicked (EventData As MouseEvent)
If File.Exists(File.DirApp,"data/server.db3")=False Then
sql1.InitializeSQLite(File.DirApp, "data/server.db3", True)
CreateData
Create_server_detail
sql1.close
Else
File.Delete(File.DirApp,"data/server.db3")
sql1.InitializeSQLite(File.DirApp, "data/server.db3", True)
CreateData
Create_server_detail
sql1.close
End If
Dim message, title As String
message = "Server Database Generated Successful."
title = "Successful"
Msgbox.Show(message, title)
End Sub
Sub Encrypt(testo As String) As Byte()
Dim ByteArray() As Byte
ByteArray=cifro.Encrypt(testo.GetBytes("UTF8"), "xxxx")
Return ByteArray
End Sub
and below is B4A code:
B4X:
Sub get_server_detail
Dim Row As Int
Dim Cursor1 As Cursor
Dim RowNumber = 0 As Int
Cursor1 = sql1.ExecQuery("SELECT server_database_name,server_host,server_user,server_password,server_port FROM tbl_server_detail")
If Cursor1.RowCount > 0 Then 'check if entries exist
RowNumber = Cursor1.RowCount 'initialize the ID list
For Row = 0 To RowNumber - 1
Cursor1.Position = Row 'set the Cursor to each row
server_database_name = Cursor1.GetString("server_database_name")
server_host=Cursor1.GetString("server_host")
server_user = Cursor1.GetString("server_user")
server_password = Cursor1.GetString("server_password")
server_port = Cursor1.GetString("server_port")
Next
Log(server_database_name)
Dim string_encrypt As String
Dim b() As Byte = conv.StringToBytes(server_database_name,"UTF8")
string_encrypt = Decrypt(b) '<== get the error here
Log(string_encrypt)
End If
End Sub
Sub Decrypt(testo() As Byte) As String
Dim ByteArray() As Byte
ByteArray=cifro.Decrypt(testo, "xxxx")
Return BytesToString(ByteArray, 0, ByteArray.Length, "UTF8")
End Sub
here is error msg
B4X:
** Service (starter) Create **
\����^�C(x�n=�0Ɗ����!7+�-����Fu0���[��I��"qM��2
Error occurred on line: 70 (Starter)
java.lang.RuntimeException: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.EVP_CipherFinal_ex(Native Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLCipher.doFinalInternal(OpenSSLCipher.java:398)
at org.apache.harmony.xnet.provider.jsse.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:434)
at javax.crypto.Cipher.doFinal(Cipher.java:1111)
at anywheresoftware.b4a.object.B4XEncryption.Decrypt(B4XEncryption.java:47)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:668)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:334)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:244)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.hirise.tcpnfcloc.starter.onCreate(starter.java:53)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2627)
at android.app.ActivityThread.access$1600(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
** Service (starter) Start **
please help me.