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.