Results 1 to 20 of 21

Thread: sending encrypted data via mail using smtp

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: sending encrypted data via mail using smtp

    Quote Originally Posted by wysota View Post
    The order while sending should be:
    1. encrypt file
    2. encode it with base64
    3. divide it into blocks 64 (or 80 or whatever) bytes each
    4. concatenate blocks using newlines (\r\n)
    5. pass the result into the mail stream adding a base64 header

    when receiving a mail:
    1. parse headers
    2. concatenate lines
    3. base64 decode into QByteArray
    4. decrypt
    5. pass the result into the stream
    Did you mean this below code

    while sending
    Qt Code:
    1. int MAX_BLK_SIZE = 64;
    2. string sSrcBlk = dat;
    3. int hManyBlks = sSrcBlk.length()/MAX_BLK_SIZE;
    4. char** pSrcBlk = new char*[hManyBlks + 1];
    5.  
    6. for( int i=0; i < hManyBlks; ++i )
    7. {
    8. pSrcBlk[i] = new char[MAX_BLK_SIZE + 1];
    9. memcpy(pSrcBlk[i], sSrcBlk.data(), MAX_BLK_SIZE);
    10. }
    11.  
    12. //append the block
    13. for( int i=0; i < hManyBlks; ++i )
    14. QString blks = QString( pSrcBlk[i] ) + QString("\r\n");
    15.  
    16. //send blks through mail stream adding base64 header
    To copy to clipboard, switch view to plain text mode 

    while receiving
    Qt Code:
    1. 1) parse -- How to do this ?
    2. 2) contcatenate lines -- How to do this ?
    3. 3) base64 decode into ByteArray -- I can do it
    4. 4) decrypt ---- I can do it
    5. 5) pass the result into the stream -- I can do it
    To copy to clipboard, switch view to plain text mode 
    Last edited by vermarajeev; 13th August 2007 at 15:30.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: sending encrypted data via mail using smtp

    Quote Originally Posted by vermarajeev View Post
    I'm unable to understand these points
    3. divide it into blocks 64 (or 80 or whatever) bytes each ---- need some more explanation
    4. concatenate blocks using newlines (\r\n) ----- ---- need some more explanation
    5. pass the result into the mail stream adding a base64 header --------- ---- need some more explanations
    If possible please correct me with my code above and tell me how can I achieve the above three points
    Ad 3. and 4. base64 encoded data is a string of characters. The usual thing to do is to divide the long line into shorter lines.
    Ad 5. Make the result part of your outgoing mail embedding it into proper attachment headers.

    Something like:
    Qt Code:
    1. QString base64encoded; // your encoded data here
    2. while(base64encoded.length()>64){
    3. slist << base64encoded.left(64);
    4. base64encoded.remove(0, 64);
    5. }
    6. slist << base64encoded; // remainder
    7.  
    8. QString result = slist.join("\x0a\x0C"); // \r\n
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by vermarajeev View Post
    while receiving
    Qt Code:
    1. 1) parse -- How to do this ?
    2. 2) contcatenate lines -- How to do this ?
    3. 3) base64 decode into ByteArray -- I can do it
    4. 4) decrypt ---- I can do it
    5. 5) pass the result into the stream -- I can do it
    To copy to clipboard, switch view to plain text mode 
    Oh come on... I'm not going to write a mail client for you Use your head - think.

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: sending encrypted data via mail using smtp

    Thank you wysota,
    It is a long time that I have send the post and till then I have been trying to solve the problem. And the good thing is I'm just near to solution. I'm able to send the encrypted data, and also able to decode it but only partial i.e only half. I think there is a problem using std::string with binary data.

    I'm just trying to figure out and let you know if I get.
    I'm really sorry to ask for solution without myself going in depth.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: sending encrypted data via mail using smtp

    Why do you use std::string for binary data? It should be safe anyway (contrary to using QString)... You should simply use QByteArray and its data() method if you need to operate on the raw data directly.

Similar Threads

  1. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.