Sample code for 30+ languages & platforms
C++

Base64 Encode/Decode a String

See more Encryption Examples

_LANGUAGE_ example to base-64 encode and decode a string.

Chilkat C++ Downloads

C++
#include <CkBinData.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkBinData bd;

    const char *s = "A friend called me up the other day and talked about investing in a dot-com that sells lobsters. Internet lobsters. Where will this end? --Donald Trump";

    success = bd.AppendString(s,"utf-8");

    const char *strBase64 = bd.getEncoded("base64");
    std::cout << strBase64 << "\r\n";

    // To decode:
    CkBinData bd2;
    bd2.AppendEncoded(strBase64,"base64");

    const char *decoded = bd2.getString("utf-8");
    std::cout << decoded << "\r\n";
    }