Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private TextField1 As B4XView
Private TextField2 As B4XView
Private TextField3 As B4XView
Dim myPassword As String = "12345678"
End Sub
Public Sub Initialize
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub Button1_Click
'xui.MsgboxAsync("Hello world!", "B4X")
Dim myString As String = TextField1.Text
Dim myEncryptedData() As Byte
Dim myStringFromTextField2 As String
Dim myByteToBeDecrypted() As Byte
Dim myDecriptedString As String
myEncryptedData = EncryptText(myString, myPassword)
'Log(myEncryptedData)
Log(DecryptText(myEncryptedData, myPassword))
TextField2.Text = BytesToString(myEncryptedData, 0, myEncryptedData.Length,"utf-8")
myStringFromTextField2 = TextField2.Text
myByteToBeDecrypted = myStringFromTextField2.GetBytes("utf-8") ' <----- This generates a byte array different from myEncriptedData byte array
myDecriptedString = DecryptText(myByteToBeDecrypted, myPassword) ' <----- This line make the program crashed. Maybe is due to myByteToBeDecrypted byte array is different from myEncriptedData byte array
TextField3.Text = myDecriptedString
End Sub
Sub EncryptText(text As String, password As String) As Byte()
Dim c As B4XCipher
Return c.Encrypt(text.GetBytes("utf-8"), password)
End Sub
Sub DecryptText(EncryptedData() As Byte, password As String) As String
Dim c As B4XCipher
Dim b() As Byte = c.Decrypt(EncryptedData, password)
Return BytesToString(b, 0, b.Length, "utf-8")
End Sub