Results 1 to 5 of 5

Thread: TripleDESCryptoServiceProvider in C++ using OpenSSl

  1. #1
    Join Date
    Nov 2012
    Location
    Poland/UK
    Posts
    28
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Thumbs up TripleDESCryptoServiceProvider in C++ using OpenSSl

    Hello, I have a problem with TripleDESCryptoServiceProvider function. I need it to ensure backward compatibility in our app.
    The general problem is that 3DES decoder doesn't work properly. If You have any suggestions how to fix my problem please answer

    Best regards.

    C# code:
    Qt Code:
    1. CryptoStream cryptoStream = new CryptoStream(memoryStream, new TripleDESCryptoServiceProvider
    2. {
    3. Key = passwordDeriveBytes.GetBytes(24),
    4. IV = passwordDeriveBytes.GetBytes(8)
    5. }.CreateDecryptor(), CryptoStreamMode.Read);
    6. StreamReader streamReader = new StreamReader(cryptoStream);
    7. string result = streamReader.ReadToEnd();
    8. memoryStream.Close();
    9. cryptoStream.Close();
    10. return result
    To copy to clipboard, switch view to plain text mode 

    QT/C++ Code:

    Qt Code:
    1. byte *key = passwordDeriveBytes.GetBytes(24); // returns same value as c# function
    2. byte *iv = passwordDeriveBytes.GetBytes(8); // returns same value as c# function
    3.  
    4. DES_key_schedule ks1, ks2;
    5. QByteArray code1 = QByteArray::fromHex(code.toUtf8());
    6. code1 = QByteArray::fromBase64(code1);
    7.  
    8. /*
    9.   QString string1 = "";
    10.   for(int i = 0; i < 24; i++){
    11.   string1.append(QString::number(key[i], 16) + "-");
    12.   }
    13.   QString string2 = "";
    14.   for(int i = 0; i < 8; i++){
    15.   string2.append(QString::number(iv[i], 16) + "-");
    16.   }
    17.   */
    18.  
    19. //////////////////////////// something is wrong /////////////////////////////////////////////////
    20. byte *output = new byte[code1.size()];
    21.  
    22. DES_set_key((C_Block *)key, &ks1);
    23. DES_set_key((C_Block *)iv, &ks2);
    24.  
    25. DES_ecb2_encrypt((C_Block *)code1.constData(),(C_Block *)output, &ks1, &ks2, DES_DECRYPT);
    26. QString rval = QByteArray::fromRawData((char *)output, code1.size());
    27. return rval;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2012
    Location
    Poland/UK
    Posts
    28
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TripleDESCryptoServiceProvider in C++ using OpenSSl

    Come on..., no one wants to help me?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: TripleDESCryptoServiceProvider in C++ using OpenSSl

    What is the question?
    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.


  4. #4
    Join Date
    Nov 2012
    Location
    Poland/UK
    Posts
    28
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TripleDESCryptoServiceProvider in C++ using OpenSSl

    Sorry, I should precise my problem.
    Why my C++ code doesn't work properly ? Is any difference between OpenSSL and Microsoft 3DES ?
    I did something wrong ? I don't have enough experience with C#

    I think that something is wrong in this code:
    Qt Code:
    1. byte *output = new byte[code1.size()];
    2. DES_set_key((C_Block *)key, &ks1);
    3. DES_set_key((C_Block *)iv, &ks2);
    4.  
    5. DES_ecb2_encrypt((C_Block *)code1.constData(),(C_Block *)output, &ks1, &ks2, DES_DECRYPT);
    6. QString rval = QByteArray::fromRawData((char *)output, code1.size());
    7. return rval;
    To copy to clipboard, switch view to plain text mode 

    Just I want to rewrite this code from c# to c++/qt using OpenSSL

    Qt Code:
    1. CryptoStream cryptoStream = new CryptoStream(memoryStream, new TripleDESCryptoServiceProvider
    2. {
    3. Key = passwordDeriveBytes.GetBytes(24),
    4. IV = passwordDeriveBytes.GetBytes(8)
    5. }.CreateDecryptor(), CryptoStreamMode.Read);
    6. StreamReader streamReader = new StreamReader(cryptoStream);
    7. string result = streamReader.ReadToEnd();
    8. memoryStream.Close();
    9. cryptoStream.Close();
    10. return result
    To copy to clipboard, switch view to plain text mode 

    My C++ passwordDeriveBytes.GetBytes working well
    This page may be usefull: http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

    Thank You for any help
    Last edited by Coder5546; 12th December 2014 at 18:57.

  5. #5
    Join Date
    Aug 2015
    Posts
    1
    Platforms
    Windows

    Default Re: TripleDESCryptoServiceProvider in C++ using OpenSSl

    Hi,
    Were you able to solve this finally? I am facing the same issue and am stuck.

Similar Threads

  1. QNetworkAccessManager put openssl
    By MCSpy in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2014, 10:32
  2. Use openssl 1.0.0 with Qt 4.8.3 on Mac
    By sfcheng77 in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2012, 00:26
  3. Qt openssl aes lib
    By zgulser in forum Qt Programming
    Replies: 5
    Last Post: 11th July 2012, 12:23
  4. QT and OpenSSL EVP.h
    By TCB13 in forum Newbie
    Replies: 16
    Last Post: 4th September 2011, 20:04
  5. Qt 4.5 Openssl problem
    By srikanth_trulyit in forum Installation and Deployment
    Replies: 1
    Last Post: 10th June 2009, 09:54

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.