Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim crypto As B4XCipher
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim SQL1 As SQL
Dim database As String
Private Button1 As Button
Private Button2 As Button
Private EditText1 As EditText
Private Label1 As Label
Private Label2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("cryptdb")
'Test crypto su DB
'inizializzo il database
database = DBUtils.CopyDBFromAssets ("crypt.db")
SQL1.Initialize(database, "crypt.db", True)
End Sub
Sub Encrypt(testo As String) As Byte()
Dim ByteArray() As Byte
ByteArray=crypto.Encrypt(testo.GetBytes("UTF8"), "xxxxxx") ' This is line 54
Return ByteArray
End Sub
Sub Decrypt(testo() As Byte) As String
Dim ByteArray() As Byte
ByteArray=crypto.Decrypt(testo, "xxxxxx")
Return BytesToString(ByteArray, 0, ByteArray.Length, "UTF8")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button2_Click
'Rileggo Valori dentro Configura
'Lettura DB valori su una riga
Dim Query As String
Dim Curs As Cursor
Dim risultato() As Byte
Try
Query = "SELECT * FROM crypto WHERE id = 1"
Curs = SQL1.ExecQuery(Query)
Curs.Position = 0
risultato = Curs.GetString("testo").GetBytes("UTF8")
Curs.Close
Catch
ToastMessageShow("Problem",True)
End Try
Dim vedi As String
vedi = BytesToString(risultato, 0, risultato.Length, "UTF8")
ToastMessageShow(vedi, True)
LogColor(vedi, Colors.Red)
Label1.Text = Decrypt(risultato)
End Sub
Sub Button1_Click
Dim test As String
test = EditText1.Text
'test = test.Replace("'", "''") ' <------ In questo modo anche se presente l'apostrofo è ok ;)
'Crypto stringa
Dim trasformobyte() As Byte
Dim string_crypt As String
trasformobyte = Encrypt(test)
string_crypt = BytesToString(trasformobyte, 0, trasformobyte.Length, "UTF8")
Log(string_crypt)
'Inserisco nel DB testo crypto
SQL1.ExecNonQuery("UPDATE crypto SET testo ='" & string_crypt & "'")
'Rileggo da DB
Dim Query As String
Dim Curs As Cursor
Dim risultato() As Byte
Try
Query = "SELECT * FROM crypto WHERE id = 1"
Curs = SQL1.ExecQuery(Query)
Curs.Position = 0
'Inserisco nella label2 testo crypto
risultato = Curs.GetString("testo").GetBytes("UTF8")
Curs.Close
Catch
ToastMessageShow("Problem",True)
End Try
Label2.Text = BytesToString(risultato, 0, risultato.Length, "UTF8")
End Sub