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