The following routine encodes a string into it's Base64 equivalent using the default string to byte conversion. Note that lines are not broken at 76 characters. This is the correct rule for most web applications.
The net collection provides routines to perform Base64 encoding. They are oriented towards encoding attachments for inclusion in email. In this situation line length is limited to 76 characters. Most other applications, for example HTTP Basic Authentication, don't have this limitation.
Base64 is only defined for 8-bit values, so some conversion must be used to turn string characters to bytes. The implementation above uses the UTF-8 encoding, which is the default for string ports.