-1

I want to encrypt the data of a database and to do this, I used AES_128 in this link for encryption.

The result of encryption is a QByteArray and the QByteArray is saved on the text file in the correct shape and I could decode it correctly, but and I need to convert it to the QString and reverse to QByteArray to store and read it on the Sqlite DB. I tried some options like

QByteArray encodedText; QString DataAsString = QString(encodedText);

and

string DataAsString1 = encodedText.toStdString();

and

QString DataAsString = QTextCodec::codecForName("UTF-8") >toUnicode(encodedText);

and other solutions like this link, but the outputs of these options aren't in the correct way. Because after casting, I couldn't convert the encoded text to decoded correctly.

This is the input string of encoded text: "\x14r\xF7""6#\xFE\xDB\xF0""D\x1B\xB5\x10\xEDx\xE1""F" and these are the outputs for the different options: \024r�6#���D\033�\020�x�F and \024r�6#���D\033�\020�x�F

Does anybody suggestion about the right conversion?

Ihor Baklykov
  • 543
  • 7
  • 24
Javad_R
  • 1
  • 3
  • 1
    Normally you'd try a specialized binary to text encoding such as base 64. Currently it seems you are trying to perform binary to text as a *character decoding* operation. However, the randomized bytes within the ciphertext are not representing text at all. – Maarten Bodewes Nov 07 '22 at 16:00
  • @Maarten Bodewes Maybe I explained in wrong way. At this moment I want to convert the QArrayByte to QString. After encoding, for some string, the output of the encoding is "\x14r\xF7""6#\xFE\xDB\xF0""D\x1B\xB5\x10\xEDx\xE1""F", while it change after conversion to QString, the output change to \024r�6#���D\033�\020�x�F . – Javad_R Nov 09 '22 at 06:19
  • As nobody could help, I asked this question again in the qt forum and shared the result with you. [This is the link.](https://forum.qt.io/topic/140679/convert-qbytearray-to-qstring) – Javad_R Nov 14 '22 at 06:58
  • Yes, instead of using a specialized binary to text encoding you can also just store it as binary. News at eleven. – Maarten Bodewes Nov 22 '22 at 23:34

1 Answers1

1

try to use this: QString QString::fromUtf8(const QByteArray &str)

Rafael Z. B. Bravo
  • 1,022
  • 10
  • 23