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.

Contents

[Hide]

  • 1 sample code
  • 2 base64 encoding
  • 3 base64 Decoding
  • 4 tips


ExampleCode

 # 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.

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.