i need to Encrypt Text with B4XCipher ,save it to sqlite (as string) ,then able to get it back
this code not work with me
B4X:
Sub MakeText(text As String) As String
Dim c As B4XCipher,CC() As Byte
CC=c.Encrypt(text.GetBytes("utf8"),PPWW)
Return BytesToString(CC,0,CC.Length, "utf8")
End Sub
Sub GetMyText(tx1 As String) As String
Dim En1() As Byte =tx1.GetBytes("utf8")
Dim c As B4XCipher
Dim b() As Byte = c.Decrypt(En1,PPWW)
Return BytesToString(b, 0, b.Length, "utf8")
End Sub
Sub MakeText(text As String) As String
Dim c As B4XCipher,CC() As Byte
CC=c.Encrypt(text.GetBytes("UTF-8"),PPWW)
Dim B64 As StringUtils
Return B64.EncodeBase64(CC)
End Sub
Sub GetMyText(tx1 As String) As String
Dim B64 As StringUtils
Dim En1() As Byte =B64.DecodeBase64(tx1)
Dim c As B4XCipher
Dim b() As Byte = c.Decrypt(En1,PPWW)
Return BytesToString(b, 0, b.Length, "UTF-8")
End Sub
You should not use BytesToString on the encrypted data. It is not a String.
Convert the encrypted data to base64 and save this base64 string to your Database.
When reading from Database you start with decoding the base64 to a bytearray. Then decrypt this bytearray.
This library allows you to encrypt or decrypt data using the AES encryption method. To prevent confusion, B4XEncryptino is not a b4xlib and is made of three platform specific libraries: B4XEncryption - B4A jB4XEncryption - B4J iEncryption - B4i (Encrypt and Decrypt methods) It is simple to use...