title: Converting QString/QChar to be accepted with Crypto++
body: <p>I want to make program that encrypts (later decrypts) user inputted string.
  Here is beginning for encryption:</p>
  
  <pre><code>QString getData = ui-&gt;text-&gt;toPlainText(); //Data to process
  std::string output; //Result will be Base32 encoded string, so std::string is fine.
  </code></pre>
  
  <p>Now, I have to convert <code>QString</code> to <code>char*</code> or <code>std::string</code> so it can be accepted with Crypto++. I thought that <code>QByteArray</code> would be fine, as it has <code>.data()</code> function, which returns <code>char *</code>. (<code>getData</code> always 17 or more bytes long: CryptoPP requires at least 17 bytes for AES encryption).
  So, I have used following code:</p>
  
  <pre><code>QByteArray data;
  data.append(getData);
  
  //Creating key and iv:
  
  //Creating AES encryptor:
  
  //Encrypting AES and Base32:
  CryptoPP::StringSource ss((const byte*)data.data(), data.size() , true,
      new CryptoPP::StreamTransformationFilter( Encryptor,
          new CryptoPP::Base32Encoder(
                  new CryptoPP::StringSink(output)
          ) // Base32Encoder
      ) // StreamTransformationFilter
  ); // StringSource
  
  ui-&gt;text-&gt;clear();
  getData = output.c_str();
  ui-&gt;text-&gt;setText(getData);
  </code></pre>
  
  <p>Everything is seems to be fine. But I want it to support non-ASCII characters (I mean russian, lithuanian etc.). After decryption they change to <code>?</code>. How could I fix this? I understand, that <code>std::string</code> doesn`t support them.</p>
  
  <hr>
  
  <p>EDIT: Here is updated code:</p>
  
  <p>Encryption:</p>
  
  <pre><code>QString getData = ui-&gt;text-&gt;toPlainText(); //Data to process
  std::string output;
  
  QByteArray data = getData.toUtf8();
  
  //Creating key and iv: &lt;..&gt;
  
  //Creating AES encryptor: &lt;..&gt;
  
  //Encrypting AES and Base32:
  CryptoPP::StringSource ss((const byte*) data.data(),getData.size()*2, true,
      new CryptoPP::StreamTransformationFilter( Encryptor,
          new CryptoPP::Base32Encoder(
                  new CryptoPP::StringSink(output)
          ) // Base32Encoder
      ) // StreamTransformationFilter
  ); // StringSource
  
  ui-&gt;text-&gt;clear();
  getData = output.c_str();
  ui-&gt;text-&gt;setText(getData);
  </code></pre>
  
  <p>And decryption:</p>
  
  <pre><code>QString getData = ui-&gt;text-&gt;toPlainText();
  QByteArray data;
  data.append(getData);
  std::string output;
  
  //Creating key and iv:
  byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ],
        iv[ CryptoPP::AES::BLOCKSIZE ];
  
  //Memsetting them: (randomization needed)
  ::memset( key, 0x01, CryptoPP::AES::DEFAULT_KEYLENGTH );
  ::memset(  iv, 0x01, CryptoPP::AES::BLOCKSIZE );
  
  //Creating AES decryptor:
  CryptoPP::CBC_Mode&lt;CryptoPP::AES&gt;::Decryption decryptor( key, sizeof(key), iv );
  
  //Decrypting Base32 and AES
  CryptoPP::StringSource ss((const byte*) data.data(), data.size(), true,
      new CryptoPP::Base32Decoder(
          new CryptoPP::StreamTransformationFilter( Decryptor,
              new CryptoPP::StringSink(output)
          ) // StreamTransformationFilter
      ) // Base32Encoder
  ); // StringSource
  
  ui-&gt;text-&gt;clear();
  getData = QString::fromUtf8(output.c_str());
  ui-&gt;text-&gt;setText(getData);
  </code></pre>
  
  <p>Does it have any bugs I have missed?</p>