base64 - C++ implementation

Working on cs3web, a C++ application to assemble web pages, lead to a need to use web cookies. Although cookies do not need to be either encrypted or converted into a "safe" format, I felt it was best to do both (or at least have the ability to be able to do either). For instance, care needs to be taken to have a cookie that has a value containing a simi-colon (ie: ";"). Also, when placing values in a URL, care needs to be taken for certain characters such as an ampersand (ie: "&"), percent (ie: "%"), etc.

The "safe" format I chose was base64 as this is a common safe format and the ability to convert things to and from base64 would be useful elsewhere. The C++ class/object to do this is pretty straight forward but only works on fixed length buffers. Although it would be possible to do base64 conversions on a stream and pad when the stream is closed, this class does not support streams directly itself.

The following is a list of some of the features of this simple base64 conversion class:

  • small
  • simple
  • algorithm is straight forward (based on wikipedia base64 page algorithm)
  • can auto-split the output at a specific line length
  • scrubs input base64 value to strip invalid chars (such as newlines)

Please first be familiar with the information and license information as detailed in the disclaimer page and then read the documentation page for usage and other information and see the download page for obtaining the source code.