Android Question Reading encrypted string and decoding it into a string array

Stephen A Wolfe

Member
Licensed User
Here's some code I have:
B4X:
    Dim ReadString As String
    Dim EncryptedString As Object
    Dim MyPhone As PhoneId
And...
    EncryptedString = File.ReadString(File.DirRootExternal, "MyFolder/MyFile.txt")
    ReadString = DecryptText(EncryptedString, MyPhone.GetDeviceId)
    FileLoc = Regex.Split(CRLF, ReadString)
    Msgbox(FileLoc(1), "The line of decoded array I need")

I'm getting an error "String cannot be cast to Byte". It seems like this should work. The error occurs for the decrypt line. I am saving the file using the reverse method (
File.WriteString(File.DirRootExternal, "MyFolder/MyFile.txt", EncryptedString)

I have tried so many different things and am completely stumped.
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

Stephen A Wolfe

Member
Licensed User
Post the code for DecryptText
Ooops, sorry. Here it is:
B4X:
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, "utf8")
End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0