WEB开发网
开发学院手机开发Symbian 开发 Symbian 中字符串 转码 base64 阅读

Symbian 中字符串 转码 base64

 2010-05-06 17:24:00 来源:WEB开发网   
核心提示:需要头文件及库:imcvcodc.h imut.lib用到的类:TImCodecB64编码:HBufC8* CBase64Handler::Base64EncodeLC( const TDesC8 & aSourceBuf ){TImCodecB64 B64;buffer8 = HBufC8::NewL( aSourc

需要头文件及库:

imcvcodc.h imut.lib

用到的类:

TImCodecB64

编码:

HBufC8* CBase64Handler::Base64EncodeLC( const TDesC8 & aSourceBuf )

{

TImCodecB64 B64;

buffer8 = HBufC8::NewL( aSourceBuf.Length() + aSourceBuf.Length()/3 );

B64.Initialise();

TPtr8 buffPtr = buffer8->Des();

B64.Encode( aSourceBuf, buffPtr );

return buffer8;

}

HBufC8* CBase64Handler::Base64EncodeLC( const TDesC16 & aSourceBuf )

{

buffer16 = HBufC8::NewLC( aSourceBuf.Length() );

buffer16->Des().Copy( aSourceBuf );

return Base64EncodeLC( *buffer16 );

}

结果显示:

dGhpcyBpcyBOZXNOOQ==

解码:

HBufC8* CBase64Handler::Base64DecodeLC( const TDesC8 & aSourceBuf )

{

TImCodecB64 B64;

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

B64.Initialise();

TPtr8 buffPtr = buffer->Des();

B64.Decode( aSourceBuf, buffPtr );

return buffer;

}

结果显示:

this is test!

测试方法:

CBase64Handler* Handler = CBase64Handler::NewL();

HBufC8* encodeBuf = Handler->Base64EncodeLC(_L("this is test!"));

HBufC *enbuff16 = HBufC::NewLC( (*encodeBuf).Length() );

enbuff16->Des().Copy( *encodeBuf );

console->Write( enbuff16->Des() );

console->Write( _L(" ") );

HBufC8* decodeBuf = Handler->Base64DecodeLC( ( *encodeBuf ) );

HBufC *debuff16 = HBufC::NewLC( (*decodeBuf).Length() );

debuff16->Des().Copy( *decodeBuf );

console->Write( debuff16->Des() );

console->Write( _L(" ") );

CleanupStack::PopAndDestroy(4);

Tags:Symbian 字符串 base

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