From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
Converts a String to Base64 format.
result = EncodeBase64(str [,lineWrap])
|result||String||The Base64 representation of str.|
|str||String||The String expression to be converted to Base64 format.|
|lineWrap||Integer||Specifies the maximum number of characters per line.
The default value is 76, which is the line length specified by the Base-64 Content Transfer Encoding used in MIME. If you specify a value of 0, EncodeBase64 will not insert any linebreaks. Line breaks are always CR + LF regardless of platform.
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 ReplaceLineEndings as appropriate.
The following code encodes UTF-8 text for transmission without line breaks:
Var encodedText As String = EncodeBase64(myText, 0)
// encodedText is "SGVsbG8sIHdvcmxkIQ=="