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

Discussion in 'Android Questions' started by hasexxl1988, Apr 3, 2018.

  1. hasexxl1988

    hasexxl1988 Active Member Licensed User

    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:

    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
    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")

    End Sub
    B4A Logfile:

    Value Code:VGhvbWFz
    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?
  2. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    Both examples seem to be encoding the value, try decoding on your B4A sub instead of encoding.
  3. Lee Gillie CCP

    Lee Gillie CCP Active Member Licensed User

    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....

    Last edited: Apr 3, 2018
  4. OliverA

    OliverA Well-Known Member Licensed User

    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice