Method
EncodeBase64
Description
Converts a String to Base64 format.
Usage
result = EncodeBase64(str, lineWrap)
Part |
Type |
Description |
---|---|---|
result |
The Base64 representation of str. |
|
str |
The String expression to be converted to Base64 format. |
|
lineWrap |
Optional: Specifies the maximum number of characters per line. |
Notes
Base64 is used for email file attachments. SMTP was designed around the ASCII encoding, so it assumes that characters below ASCII 32 are control codes and it doesn't expect codes above ASCII 127. EncodeBase64 lets you encode arbitrary binary data into a 64-character alphabet composed of the printable ASCII characters. Three bytes of input become four characters of output. EncodeBase64 is also used in authentication schemes as a way to send an encryption key or hash value through a link that expects text.
The DecodeBase64 function performs the reverse operation, taking a Base64 expression and converting it to the original data.
If you tell EncodeBase64 to line wrap and want a different line ending than CRLF, you'll need to use String.ReplaceLineEndings as appropriate.
Warning
On Android, any value other than 76 is treated as 0 (no line wrap).
Sample code
The following code encodes UTF-8 text for transmission without line breaks:
Var myText As String = "Hello, world!"
Var encodedText As String = EncodeBase64(myText, 0)
' encodedText is "SGVsbG8sIHdvcmxkIQ=="
Compatibility
All project types on all supported operating systems.
See also
DecodeBase64 function.