Base64 encoding and decoding on the Symbian Platform

Source: Internet
Author: User
Tags encode string

The timcodecb64 class is a base64 encoding and decoding class provided by the Symbian platform. You may not find the description about the base64 encoding and decoding class in the SDK of the official documentation. However, this class does exist in the SDK. Here we provide a simple example of the timcodecb64 class usage.

Sample Code

# Include "imcvcodc. H" // declare the header file in base64
 
Static hbufc8 * base64encodelc (const tdesc8 & asourcebuf)
{
Timcodecb64 b64;
// Using base64 the size is increased by 1/3.
Hbufc8 * buffer = hbufc8: newl (asourcebuf. Length () + asourcebuf. Length ()/3 );
B64.initialise ();
Tptr8 buffptr = buffer-> des ();
B64.encode (asourcebuf, buffptr );
Return buffer;
}
 
Static hbufc8 * base64decodelc (const tdesc8 & asourcebuf)
{
Timcodecb64 b64;
Hbufc8 * buffer = hbufc8: newlc (asourcebuf. Length ());
B64.initialise ();
Tptr8 buffptr = buffer-> des ();
B64.decode (asourcebuf, buffptr );
Return buffer;
}

Base64 encoding

// Encode string to base64 encoding with clean Stack
Hbufc8 * encodebuf = stringutil: base64encodelc (_ L8 ("this is test "));
// Change to tdesc16
Hbufc * buff16 = hbufc: newlc (PTR. Length ());
Buff16-> des (). Copy (PTR );
// Do something ....
...
// Clean Buffer
Cleanupstack: popanddestroy (2 );

Result

Vghpcybpcyb0zxn0

 

Base64 Decoding

// Decode base64 encoding with clean Stack
Hbufc8 * decodebuf = stringutil: base64decodelc (_ L8 ("vghpcybpcyb0zxn0 "));
 
// Change to tdesc16
Hbufc * buff16 = hbufc: newlc (PTR. Length ());
Buff16-> des (). Copy (PTR );
// Do something
...
// Clean Buffer
Cleanupstack: popanddestroy (2 );

Result

This is test

 

Prompt

In addition to the header file "imcvcodc. H", you also need to add imut. lib to The. MMP file.

 

Retrieved from "http://wiki.forum.nokia.com/index.php/Symbian%E5%B9%B3%E5%8F%B0%E4%B8%8BBase64%E7%BC%96%E7%A0%81%E5%8F%8A%E8%A7%A3%E7%A0%81"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.