Base64, Quoted Printable and UU Encoding and Decoding

in
Platforms:

It sometimes happen when writing connected application that you need to manipulate data in Base64, Quoted Printable or UU format. This is fairly easy with Symbian OS as three simple classes, all derivating from TImCodec, will do the job for you:

  • TImCodecB64 for Base64,
  • TImCodecQP for Quoted-Printable,
  • TImCodecUU for UU format.

Their usage is similar and fairly simple:

#include <imcvcodc.h>

void DoBase64Encoding(const TDesC8& aSourceData, TDes8& aEncodedData)
{
    TImCodecB64 b64enc;
    b64enc.Initialise();
    b64enc.Encode(aSourceData,aEncodedData);
}

void DoBase64Decoding(const TDesC8& aSourceData, TDes8& aDecodedData)
{
    TImCodecB64 b64dec;
    b64dec.Initialise();
    b64dec.Decode(aSourceData,aDecodedData);
}

Don't forget to link against imut.lib.

Here is a cool online tool to do some online Base 64 encoding / decoding: http://gtools.org/tool/base64-encode-decode/

Tutorial posted September 6th, 2007 by eric categories [ ]

Re: Base64, Quoted Printable and UU Encoding and Decoding

It would be good to know how to encode URL queries - trying to use EscapeUtils::EscapeEncodeL( ..., EscapeUtils::EEscapeQuery ) always seemed to result in my application crashing.
Some perl to show how to decode it in a CGI script would be cool too.

Re: Base64, Quoted Printable and UU Encoding and Decoding

There are quite straightforward to use:

HBufC* escapedText=EscapeUtils::EscapeEncodeL(mySourceText,EscapeUtils::EEscapeNormal);
CleanupStack::PushL(escapedText);
...
// Do whatever you want with the escaped text
...
CleanupStack::PopAndDestroy(escapedText);