c++ - Converting QString/QChar to be accepted with Crypto++ -


I want to create a program that encrypts (later decrypts) user input string is the beginning for encryption here:

  QString getData = ui- & gt; Text-> ToPlainText (); // std :: string data to process output; // result will be 32 encoded string, so std :: string is ok.  

Now, I have to convert from QString to char * or std :: string crypto + + I would have thought that QByteArray would be okay because it has the .data () function, which gives char * . ( getData is always 17 or more bytes long: Crypto PP requires at least 17 bytes for AES encryption). Therefore, I have used the following code:

  QByteArray data; Data.append (GetData); // Make AES encryptor: // Encrypting AES and Base32: CryptoPP :: StringSource SS ((byte * constant) data.data (), data.size (), true, new CryptoPP: : StreamTransformationFilter (Encryptor, New CryptoPP :: Base32Encoder (New CryptoPP :: StringSink (Production)) // Base32Encoder) // StreamTransformationFilter); // string source UI-> Text-> clear (); GetData = output.c_str (); UI- & gt; Text & gt; SetText (GetData);  

Everything looks fine. But I want to support it non-ASCII characters (I mean Russian, etc.). After decryption they are ? . How can I fix this? I understand that std :: string doesn`t support them


edit:. Code is updated here:

Encryption:

QString getData = ui- & gt; Text-> ToPlainText (); // std :: string data to process output; QByteArray Data = getData.toUtf8 (); // Creating keys and iv: & lt; .. & gt; // Creating AES Encryption: & lt; .. & gt; // Encrypting AES and Base32: CryptoPP :: StringSource SS ((byte constant) data.data (), getData.size () * 2, true, new CryptoPP :: StreamTransformationFilter (Encryptor, New CryptoPP :: Base32Encoder ( New CryptoPP :: String Sync (Output)) // Base 32 Encoder) // Stream Transformation Filter;); // string source UI-> Text-> clear (); GetData = output.c_str (); UI- & gt; Text & gt; SetText (GetData);

and decryption:

  QString getData = ui- & gt; Text-> ToPlainText (); QByteArray data; Data.append (GetData); Std :: string output; // Key Creation and iv: Byte Key [Crypopp :: AES :: DFFLBECNHNGHAD], iv [crypopp :: AES :: Blockscage]; // Making them brain: (Requires randomization): MEMSet (key, 0x01, crypopp :: AES :: DEFLBEKENNGH); :: MEMSet (iv, 0x01, crypopp :: AES :: Blocksseed); // create AES decryptor: CryptoPP :: CBC_Mode & LT; CryptoPP :: AES & gt; :: decryption decryptor (key, sizeof (key), iv); // Decrypting Base32 and AES CryptoPP :: StringSource SS ((constant byte *) data.data (), data.size (), true, new CryptoPP :: Base32Decoder (New CryptoPP :: StreamTransformationFilter (Decryptor, New CryptoPP: : StringSink (// StreamTransformationFilter) // Base32Encoder); // string source UI-> Text-> clear (); GetData = QString :: fromUtf8 (output.c_str ()); UI- & gt; Text & gt; SetText (GetData);  

Do I have any bugs that I remember?

I think you are losing data while converting from QString to QByteArray. Try it out:

  QByteArray data = getData.toUtf8 (); ... getData = QString :: fromUtf8 (output.c_str ());  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -