Hi
please take a look I explain here perhaps it will help to both of us:

I have some application wroten fully in Qt.
In the application I take input from user from line edits and receive QStrings ( ->text() function of the QLineEdit class ). Then I need to save the input ( QStrings ) encrypted to .txt file on user machine’s hdd.
For that purpose I decided to use simple XOR encryption. So I need to convert QString to QByteArray , after that make XOR between 2 byte arrays – input and encryption key and the result I need to save to .txt file so I convert the result vice versa to QString and put it to file.
Also I need to read from file the encrypted data and to check it in some place in the application. For that purpose I read encrypted from previous user input from .txt file to QString and convert it to QByteArray make decryption on QByteArray, convert the result to QString – and very sorrow I do not receive the same input as before encryption – right side of user input lost!!
Perhaps it is because of incorrect conversion QByteArray – QString and vice versa.
What is strangeous – that only for large strings data lost and for number.
I use UTF8 codec:

Qt Code:
  1. codec = QTextCodec::codecForName(“utf8”);
To copy to clipboard, switch view to plain text mode 

I get user input and write to file:

Qt Code:
  1. emailEntered = this->login->lineEdit_email->text();
  2.  
  3. keyEntered = this->login->lineEdit_code->text();
To copy to clipboard, switch view to plain text mode 
I make conversion to QByteArray and encryption:
Qt Code:
  1. QString emailToSave = QString::fromUtf8(calculateXor(this->emailEntered.toUtf8(),encryptionKey));
  2.  
  3. QString keyToSave = QString::fromUtf8(calculateXor(this->keyEntered.toUtf8(),encryptionKey));
To copy to clipboard, switch view to plain text mode 

I save to file:

Qt Code:
  1. QTextStream stream(&file);
  2. stream.setCodec(this->codec); stream<<‘‘<<emailToSave<<’\n’<<’’<<keyToSave<<’\n’<<’*’<<macAdressToSave<<’\n’; file.close();
To copy to clipboard, switch view to plain text mode 

I read from file:

Qt Code:
  1. QTextStream stream( &file );
  2. stream.setCodec(this->codec);
  3. emailFromFile.clear();
  4. keyFromFile.clear();
  5. macFromFile.clear();
  6. stream>>ch; // ‘*’
  7. stream>>ch; // email from file:
  8. while(ch!=’\n’)
  9. {
  10. emailFromFile.append(ch);
  11. stream>>ch;
  12. }
  13. stream>>ch;
  14. // ‘*’
  15. stream>>ch; // first digit of the coded license key
  16. while(ch!=’\n’)
  17. {
  18. keyFromFile.append(ch);
  19. stream>>ch;
  20. }
  21. stream>>ch; // ‘*’ stream>>ch;
  22. // first digit of mac from file
  23. while(!stream.atEnd()) // another while(stream!=’\n’)
  24. {
  25. macFromFile.append(ch);
  26. stream>>ch;
  27. }
  28. file.close();
To copy to clipboard, switch view to plain text mode 
I decrypt readed data from file:

Qt Code:
  1. QString result = QString::fromUtf8(calculateXor(this->emailFromFile.toAscii(),encryptionKey));
  2.  
  3. QString result = QString::fromUtf8(calculateXor(this->keyFromFile.toAscii(),encryptionKey));
To copy to clipboard, switch view to plain text mode 

For email I get the same as before encryption, but for key ( another user input ) there is lost numbers at the right
What is the problem? I try to fix it this time…