×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    339

    data conversion problem from encrypted string to descriptor

    Hi all,
    I am having problem to convert some encrypted data (using open ssl) to descriptor TBuf8. My code is as below

    Code:
    void send( const std::string& data )
    {
    LOG((_L("original data length = %d"), data.length()));
    
    TBuf8<1024> buf;
    chartotbuf8(data.c_str(), buf);
    
    LOG((_L("converted data length = %d"), buf.Length()));
     
    }
    and here is the conversion routine

    Code:
    void chartotbuf8 (const char *aSrc, TDes8 &aDes)
    {
      aDes = (const TUint8*)aSrc;
    }
    In log I got 1024 as original data size and converted data size is 5.While converting text data, chartotbuf8 routine is working fine. what i am doing wrong? Thanks

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,736

    Re: data conversion problem from encrypted string to descriptor

    It is a zero-termination problem. Your 6th byte is a 0, and lenght-less methods treat it as end of data.
    Pass the length explicitly, and use TDes8::Copy(const TUint8 *aBuf, TInt aLength)

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    339

    Re: data conversion problem from encrypted string to descriptor

    Thanks wizard_hu_. Passing the length in conversion routine solves the problem. For descriptor to string conversion, I am using the the following routine and facing same problem.

    Code:
    const char* descriptor8tostring(const TDesC8& descriptor)
    		{
    		TInt length = descriptor.Length();
    		HBufC8* buffer = HBufC8::NewLC(length);
    		buffer->Des().Copy(descriptor);
    		char* str = new(ELeave) char[length + 1];
    		Mem::Copy(str, buffer->Ptr(), length);
    		str[length] = '\0';
    		CleanupStack::PopAndDestroy(buffer);    
    		return str;
    		}
    how can I solve this zero-termination problem in this case? Thanks

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,736

    Re: data conversion problem from encrypted string to descriptor

    The same here. An encrypted anything is surely not a zero-terminated string. Assuming that you want the result in an std::string, you should rather write
    Code:
    std::string TDesC8ToString(const TDesC8 &aDesc)
    {
        return std::string(reinterpret_cast<const char *>(aDesc.Ptr()),aDesc.Length());
    }

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    339

    Re: data conversion problem from encrypted string to descriptor

    Thanks wizard_hu_ for your help.

Similar Threads

  1. Conversion from minus double value to String
    By archikong in forum Symbian
    Replies: 1
    Last Post: 2009-02-12, 22:59
  2. Replies: 2
    Last Post: 2008-12-25, 12:41
  3. Replies: 2
    Last Post: 2008-10-23, 20:45
  4. Conversion from TDesCArrayFlat to Descriptor
    By mdzahidul_haque in forum Symbian
    Replies: 2
    Last Post: 2008-05-31, 13:17
  5. descriptor conversion problem
    By sunny_singh in forum Symbian
    Replies: 3
    Last Post: 2005-09-05, 09:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×