'Returns Encrypted data as a base64 string
Sub EncryptText(text As String, password As String) As String
#If B4i
Dim c As Cipher
#Else
Dim c As B4XCipher
#End If
Dim Str As StringUtils
Return Str.EncodeBase64(c.Encrypt(text.GetBytes("utf8"), password))
'Return Str.EncodeBase64(c.Encrypt(c.Encrypt(text.GetBytes("utf8"), password), password)) 'If we want to double
End Sub
'Decrypts Encrypted base64 string
Sub DecryptText(EncryptedData As String, password As String) As String
'Log("PASSWORD: " & password)
#If B4i
Dim c As Cipher
#Else
Dim c As B4XCipher
#End If
Try
Dim Str As StringUtils
Dim b() As Byte = c.Decrypt(Str.DecodeBase64(EncryptedData), password)
Return BytesToString(b, 0, b.Length, "utf8")
Catch
Log($"DecryptText ${LastException}"$)
#If Debug
Log(EncryptedData)
#End If
Return "Bad Decrypt!"
End Try
End Sub