Android Question Convert Base64 String (VB.NET) to B4A Restore.

hasexxl1988

Active Member
Licensed User
Longtime User
Hello,
I have a little problem, maybe who knows:

I have a tool in VB.NET that converts a string value to a base64 string.

VB.NET Code:

B4X:
Dim byt As Byte() = Encoding.UTF8.GetBytes("Thomas")
Dim Base64
Base64= Convert.ToBase64String(byt)

The Base64 Value is: VGhvbWFz

Now I want to restore this Base64 string in B4A. I do not know where the mistake is or what I'm doing wrong. Maybe someone has an idea.

Here is the B4A code:

The Base64 Value is: VGhvbWFz
B4X:
Sub Base64(Value as String)
    Log("Value Code: " & Value)
   
    Dim su As StringUtils
    Dim bc As ByteConverter
    Dim TextBytes() As Byte = bc.StringToBytes(Value,"UTF8")

    Log(su.EncodeBase64(TextBytes))
End Sub

B4A Logfile:

B4X:
Value Code:VGhvbWFz
VkdodmJXRno=
Got result code:VGhvbWFz
** Activity (main) Resume **


When restoring the string, the result should be "Thomas" again and not "VkdodmJXRno ="

Are there any problems between VB.NET and B4A with the UTF8 encoding?
 

Lee Gillie CCP

Active Member
Licensed User
Longtime User
B4X:
    Dim su As StringUtils
    Dim MyBase64String As String = "VGhvbWFz"
    Dim MyBase64StringAsBytes() As Byte = su.DecodeBase64(MyBase64String)
    Dim s As String = BytesToString(MyBase64StringAsBytes, 0, MyBase64StringAsBytes.Length, "UTF8")
    Log( "Decoded: """ & s & """")

logs this....

Decoded: "Thomas"
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Sub Base64(Value as String)
You realize this sub encodes a given string into Base64. Your input is VGhvbWFz (as per log output shown) and therefore you and Base64 encoding this, not Thomas.
 
Upvote 0
Top