WEB开发网
开发学院手机开发Symbian 开发 Symbian平台下Base64编码及解码 阅读

Symbian平台下Base64编码及解码

 2010-05-31 19:30:00 来源:WEB开发网   
核心提示:Symbian平台下Base64编码及解码示例代码#include "imcvcodc.h" //base64 声明头文件static TPtrC8 Base64EncodeC(const TDesC8 & aSourceBuf){TImCodecB64 B64;//Using base64 the

Symbian平台下Base64编码及解码

示例代码

#include "imcvcodc.h" //base64 声明头文件

static TPtrC8 Base64EncodeC(const TDesC8 & aSourceBuf)

{

TImCodecB64 B64;

//Using base64 the size is increased by 1/3

HBufC8 * buffer = HBufC8::NewLC(aSourceBuf.Length() + aSourceBuf.Length()/3);

B64.Initialise();

TPtr8 buffPtr = buffer->Des();

B64.Encode(aSourceBuf, buffPtr);

return TPtrC8(buffer->Des());

}

static TPtrC8 Base64DecodeC(const TDesC8 & aSourceBuf)

{

TImCodecB64 B64;

HBufC8 * buffer = HBufC8::NewLC(aSourceBuf.Length());

B64.Initialise();

TPtr8 buffPtr = buffer->Des();

B64.Decode(aSourceBuf, buffPtr);

return TPtrC8(buffer->Des());

}

BASE64编码

//encode string to base64 encoding with clean stack

TPtrC8 ptr = StringUtil::Base64EncodeC(_L8("This is test"));

//Change to TDesC16

HBufC *buff16 = HBufC::NewLC(ptr.Length());

buff16->Des().Copy(ptr);

//Do something....

...

//clean buffer

CleanupStack::PopAndDestroy(2);

结果

VGhpcyBpcyB0ZXN0

BASE64编码

//Decode base64 encoding with clean stack

TPtrC8 ptr = StringUtil::Base64DecodeC(_L8("VGhpcyBpcyB0ZXN0"));

//Change to TDesC16

HBufC *buff16 = HBufC::NewLC(ptr.Length());

buff16->Des().Copy(ptr);

//Do something

...

//clean buffer

CleanupStack::PopAndDestroy(2);

结果

This is test

提示

除了需要包含”imcvcodc.h”头文件外,你还需要在.mmp文件中加入 imut.lib

Tags:Symbian 平台 Base

编辑录入:coldstar [复制链接] [打 印]
赞助商链接