Results 1 to 6 of 6

Thread: Qt openssl aes lib

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Qt openssl aes lib

    Hi,

    I wrote the following enc/dec code;

    Qt Code:
    1. AES_KEY enc_key, dec_key;
    2.  
    3. AES_set_encrypt_key((unsigned char*)p_key, 128, &enc_key);
    4. AES_ecb_encrypt((unsigned char*)textManip, (unsigned char*)enc_out, &enc_key, 1);
    5.  
    6. AES_set_decrypt_key((unsigned char*)p_key, 128, &dec_key);
    7. AES_decrypt((unsigned char*)enc_out, (unsigned char*)dec_out, &dec_key);
    To copy to clipboard, switch view to plain text mode 

    & to test it;


    Qt Code:
    1. qDebug() << "Original: " << (char*)(text);
    2. enc_out[strlen(p_Text)] = '\0';
    3. qDebug() << "Encrypted: " <<(enc_out);
    4. dec_out[strlen(p_Text)] = '\0';
    5. qDebug() << "Decrypted: " << (dec_out);
    To copy to clipboard, switch view to plain text mode 

    the output is;

    Original: WirofonPC010101
    Encrypted: ??c?'r???)?A?
    Decrypted: WirofonPC010101

    which seems ecryption is working. But I somehow thought that my encrypted characters are no good. I mean Shouldn't they like

    "31298sdf788123" or "122dfsdrwer324" ??

    Thanks..

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

    Default Re: Qt openssl aes lib

    You're dumping binary data as text (and it is not text) to the console.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Qt openssl aes lib

    Ok,

    Qt Code:
    1. QString enc_str = QString::fromUtf8(enc_out);
    To copy to clipboard, switch view to plain text mode 

    should work then..


    Added after 23 minutes:


    Hi,

    I couldn't figured out how to convert binary to txt.. Can you show me a way?
    Last edited by zgulser; 11th July 2012 at 09:57.

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

    Default Re: Qt openssl aes lib

    Quote Originally Posted by zgulser View Post
    Ok,

    Qt Code:
    1. QString enc_str = QString::fromUtf8(enc_out);
    To copy to clipboard, switch view to plain text mode 

    should work then..
    Not really.

    You can try this:
    Qt Code:
    1. qDebug() << QByteArray(enc_out, size);
    To copy to clipboard, switch view to plain text mode 
    but you need to know the size of enc_out content, strlen() will not work here in a general case as the data can contain \0 characters.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Qt openssl aes lib

    Hi,

    Qt Code:
    1. qDebug() <<"Output: " << QByteArray(encryptedData, strlen(encryptedData));
    To copy to clipboard, switch view to plain text mode 

    gave actually the same result that is;

    Encrypted: ??c?'r???)?A?

    replacing strlen with a custom one do not affect the result I guess?

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

    Default Re: Qt openssl aes lib

    Try:

    Qt Code:
    1. qDebug() << "Output:" << QByteArray(encryptedData, ...).toHex();
    To copy to clipboard, switch view to plain text mode 

    but still you can't use strlen to find the size of data. You need to read that using OpenSSL functions.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QT and OpenSSL EVP.h
    By TCB13 in forum Newbie
    Replies: 16
    Last Post: 4th September 2011, 20:04
  2. Help! Qt 4.6.0+Symbian SDK 5 does not support OPENSSL
    By coco in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 8th October 2010, 16:13
  3. problem of building qt with openssl
    By dorians58 in forum Newbie
    Replies: 1
    Last Post: 11th August 2010, 22:47
  4. Qt 4.5 Openssl problem
    By srikanth_trulyit in forum Installation and Deployment
    Replies: 1
    Last Post: 10th June 2009, 09:54
  5. Get ml.exe to build OpenSSL on VS 2005
    By captchaq in forum General Programming
    Replies: 1
    Last Post: 27th September 2008, 07:43

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.