base64 encoding

Login to reply to this topic.
Wed, 2005-02-16 10:08
Joined: 2005-02-10
Forum posts: 14
How can i encode a buffer with base64. i want to add this encoded data to xml file .

thanks

indus

Wed, 2005-02-16 13:06
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
base64 encoding
/epoc32/include/imcvcodc.h ==> TImCodecB64 class.

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Fri, 2005-03-04 01:51
Joined: 2005-03-04
Forum posts: 12
base64 encoding
This one Works and its fast and easy to use i hope it fits your goal
ihave used for image sending and sound it works superb

 Cheezy
void YourClass::EcodeBase(const TBuf8<255> Srt)
{
  ret.FillZ();
  ret.SetLength(0);
  TBuf8<64> cvt;
  TUint8 fillchar = '=';
  for(int i = 0; i < 26; i++)
  {
    cvt.Append('A' +i);
  }
  for(int i = 0; i < 26; i++)
  {
    cvt.Append('a' +i);
  }
  for(int i = 0; i < 10; i++)
  {
    cvt.Append('0' +i);
  }
  cvt.Append('+');
  cvt.Append('/');

  TUint8 c;
  for (int i = 0; i < Srt.Length(); ++i)
  {

    c = (Srt[i] >> 2) & 0x3f;
    ret.Append(cvt[c]);
    c = (Srt[i] << 4) & 0x3f;
    if (++i < Srt.Length())
        c |= (Srt[i] >> 4) & 0x0f;

    ret.Append(cvt[c]);
    if (i < Srt.Length())
    {
        c = (Srt[i] << 2) & 0x3f;
        if (++i < Srt.Length())
            c |= (Srt[i] >> 6) & 0x03;

        ret.Append(cvt[c]);

    }
    else
    {
        ++i;
        ret.Append(fillchar);
    }

    if (i < Srt.Length())
    {
        c = Srt[i] & 0x3f;
        ret.Append(cvt[c]);
    }
    else
    {
        ret.Append(fillchar);
    }
}



}
Fri, 2005-03-04 03:16
Joined: 2005-03-04
Forum posts: 12
base64 encoding
for got tell one thing

TBuf8<340> ret;

shuld bie buffer Size + 1/3

in my case
255 + (1/3) =340

u can do this dynamic but i havet had the need for it..
Tue, 2005-07-12 16:37
Joined: 2005-05-03
Forum posts: 21
Re: base64 encoding
sorry but the class does not exist into the serie60 sdk v2.0 is there any equivalent libs ?

tnx
Tue, 2005-07-12 22:57
Joined: 2005-03-04
Forum posts: 12
Re: base64 encoding
i wrote the class s60 or symbian dont have a buit in Base 64 coder/decoder you have to provide the code your self.. =) if u realy want a libary or dll you have to wite it your self.... Grin
Wed, 2005-07-13 04:16
Joined: 2004-12-03
Forum posts: 276
Re: base64 encoding
Hi,

TImCodecB64 class is not a documented class.... You can use it .....

include the header imcvcodc.h and link with imut.lib library

Dennis

Today is a gift by GOD, that's why it is called the present.

Wed, 2005-07-13 09:13
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: base64 encoding
Quote from: kaz
sorry but the class does not exist into the serie60 sdk v2.0 is there any equivalent libs ?

tnx

Well, the oldest SDK I checked was 2.1 and it contains this file. Can't you start using newer SDKs?

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Wed, 2005-07-13 11:04
Joined: 2004-12-03
Forum posts: 276
Re: base64 encoding
I used it in 1.2 SDK also

Today is a gift by GOD, that's why it is called the present.

Wed, 2005-07-13 11:28
Joined: 2004-09-06
Forum posts: 235
Re: base64 encoding
yes, the class TImCodecB64 is not documented in the SDK 1.2 and 2.0.
But the imut.lib and IMCVCODC.H do exist on these SDKs and they work fine.
Wed, 2005-07-13 12:35
Joined: 2005-05-03
Forum posts: 21
Re: base64 encoding
thanks every body, I found it and it work fine
Wed, 2007-01-31 13:04
Joined: 2005-11-30
Forum posts: 29
Re: base64 encoding
Dramatically  puzzle me: I encode a string then decode the result, it failed!!
                 :-oTImCodecB64 b64;
   b64.Initialise();
   TPtr8 result(bufferEncoded->Des() );
   if(b64.Encode(readbuffer, result) )
   {
      __LOG2("%d, %d\n", readbuffer.Length(), encodeLen);
      __LOG1("content=%S\n", &result);
      aBuffer.Append(result);
   }
   if(b64.Decode(result, readbuffer) )
   {
      __LOG2("%S, org=%S\n", &result, &readbuffer);
   }
   else
   {
      __LOG("decode failed\n");
   }
   CleanupStack::PopAndDestroy(2);
Wed, 2007-05-09 22:31
Joined: 2006-12-17
Forum posts: 4
Re: base64 encoding
we are finding some trouble using the symbian base64 decoder to decode an image data?

The same pieace of code works ok for text encoding decoding but for this image it always gives empty destination buffer.

Is there some ration on size of input and output buffers? like the output buffer must be more then "input+(input/3)" ?

did some one expreced some trouble while decoing large data all at once like a big image or voice etc. ?

S.
Mon, 2007-06-11 09:15
Joined: 2004-12-03
Forum posts: 276
Re: base64 encoding
What is the problem you are facing?

Using base64 the size is increased by 1/3. So if your input length is "x" then the target length should be "4x/3".

And TImCodecB64 works fine for both binary (e.g. jpg) and ascii data.

Encode function will panic if the target size is not sufficient.

Today is a gift by GOD, that's why it is called the present.

  • Login to reply to this topic.