Android Question Any easy way to encode base64 sring ?

gameone

Member
Licensed User
Hi i see alot about encoding/decoding image in base64, but does they are a easy way to encode just a base64 string and show up ?

I try playing with StringUtils, but got failed with using "EncodeBase64"
Thanks.
 

KMatle

Expert
Licensed User
Longtime User
Upvote 0

gameone

Member
Licensed User
Oh my bad i have read too much quickly, i know for decode it's for "encode"

You know from a world like "example" got a base64 string UTF-8
 
Upvote 0

gameone

Member
Licensed User
No body can help me ? For encode a string "example" into base64.

Basicly what i want is from "example" got "ZXhhbXBsZQ=="
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Basicly what i want is from "example" got "ZXhhbXBsZQ=="
Where is the problem? StringUtils and ByteConverter is all you need
B4X:
Dim text As String = "example"
Log(su.EncodeBase64(bc.StringToBytes(text,"utf-8")))

LogCat connected to: 05157df57d72d204
--------- beginning of main
** Activity (main) Create, isFirst = true **
ZXhhbXBsZQ==
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 
Upvote 0

Recep Cinet

Member
Licensed User
Longtime User
B4X:
Log (encodeBase64("123456"))
Log (decodeBase64("MTIzNDU2"))

B4X:
'StringUtil Library needed
'ByteConverter Library needed
public Sub encodeBase64(str As String) As String
    Dim su As StringUtils
    Dim bc As ByteConverter
    Dim byt() As Byte = bc.StringToBytes(str,"UTF-8")
    Dim out As String=su.EncodeBase64(byt)
    Return out
End Sub
public Sub decodeBase64(str As String) As String
    Dim su As StringUtils
    Dim bico As ByteConverter
    Dim byt() As Byte=su.DecodeBase64(str)
    Dim out As String=bico.StringFromBytes(byt,"UTF-8")
    Return out
End Sub
 
Upvote 0
Top