B4XBase64 encoding and decoding algorithms were developed using B4X code only, without external libraries (StringUtils).
Methods:
. URL encoding and decoding
. Image variable encoding and decoding
. Text variable encoding and decoding
. Image file encoding and decoding
. Text file encoding and decoding
. Base64 encoding and decoding
. Base64-Safe encoding and decoding
. Convert Base64 to Base64-Safe
. Convert Base64-Safe to Base64
. Validates Base64 or Base64-Safe encoding
. Character repeater
. Others
Note: You can combine the use of its methods according to your needs.
ex.
Regards.
Methods:
. URL encoding and decoding
. Image variable encoding and decoding
. Text variable encoding and decoding
. Image file encoding and decoding
. Text file encoding and decoding
. Base64 encoding and decoding
. Base64-Safe encoding and decoding
. Convert Base64 to Base64-Safe
. Convert Base64-Safe to Base64
. Validates Base64 or Base64-Safe encoding
. Character repeater
. Others
Note: You can combine the use of its methods according to your needs.
B4X:
' Initialize
Dim Base64 As B4XBase64
Base64.Initialize
Log("1.- ************** URL ************** ")
Dim s As String = $"https://www.b4x.com/android/forum/whats-new/posts/4054187/"$
Log("Encode: " & Base64.URLEncode(s))
Log("Decode: " & Base64.URLDecode(Base64.URLEncode(s)))
Log("2.- ************** IMAGE ************** ")
Dim BitmapImage As B4XBitmap = xui.LoadBitmap(File.DirAssets, "1.jpg")
Dim s As String = Base64.ImageEncode(BitmapImage, "jpg") 'or png
Log("Encode:")
Log(s)
Log("Valid: " & Base64.IsValid(s))
B4XImageView1.Bitmap = Base64.BytesToImage(Base64.Decode(s))
B4XImageView1.ResizeMode = "FILL"
Log("3.- ************** TEXT ************** ")
Dim Text As String = "This class was made only with B4X code, without external libraries."
Dim t As String = Base64.TextEncode(Text)
Log("Encode:")
Log(t)
Log("Valid: " & Base64.IsValid(t))
Log("Decode: " & Base64.BytesToText(Base64.Decode(t)))
Log("4.- ************** FILE ************** ")
Dim FileBytes() As Byte = Base64.FileToBytes(File.DirAssets, "1.jpg")
Base64.BytesToFile(xui.DefaultFolder, "1.png", FileBytes)
Log("Dir File: " & xui.DefaultFolder)
Dim s As String = Base64.Encode(Base64.FileToBytes(xui.DefaultFolder, "1.png"))
Log("Encode:")
Log(s)
Log("Valid: " & Base64.IsValid(s))
Log("5.- ************** REPEAT ************** ")
Log(Base64.Repeat("A",10))
Log(Base64.Repeat("*",15))
Log(Base64.Repeat(Chr(36),12))
Regards.
Last edited: