Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QCA problems when decrypting data from php
Forum Updated to NodeBB v4.3 + New Features

QCA problems when decrypting data from php

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
4 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kosta
    wrote on last edited by Kosta
    #1

    I am encrypting data from php and store the data to my db here is the function i use to crypt in php

    function encrypt($data, $key, $iv)
    {
    
        return openssl_encrypt(
        $data,
        'AES-256-CBC',
        $key,
        0,
        $iv
        );
    
    }
    // Here is how i use it
    $email = encrypt($email, $key, $iv);
    // iv is a 124 character long string generated randomly with a-zA-Z0-9 chars
    

    Now when i get the data back from the database on my Qt app here is what i get

    Name: £»]
    Email:  HþÔ7Þ†Ç`}3™b­­_$ßïóøb2Û]Å
    // Some chars are not visible
    

    This is what i am supposed to decrypt so i retrieve the iv from the database and use the unhashed password the user did input to decrypt

    QString KLogin::decrypt(QString data, QString key, QString iv)
    {
        // Data = the encrypted input (i loop threw the values to decrypt), key = user password, IV = what i received from the db earlier
        QCA::Initializer init;
    
        QByteArray get;
        QCA::SecureArray secured;
    
        QByteArray temp = key.toLatin1();
        QCA::SymmetricKey pass = QCA::SymmetricKey(temp);
    
    
        temp = iv.toLatin1();
        QCA::InitializationVector iv_f = QCA::InitializationVector(temp);
    
        temp = data.toLatin1();
        secured = temp;
    
        QCA::Cipher bf(QString("aes256"), QCA::Cipher::CBC, QCA::Cipher::NoPadding , QCA::Decode, pass, iv_f);
    
        get = bf.process(secured).toByteArray();
    
        QString decrypted = get;
    
        return decrypted;
    
    }
    

    I know my code is very dirty i apologize, i have been trying stuff for 5hours, and i tried to look up for the doc, but the doc i found is not really helpful...
    I'm sure i'm getting the right data since i have some std::cout set to output values and here is what i get

    IV value = 8lfSciaaaW1ZttTgWn4E616VsXnmEsUMOaE1sPbDLcCeFvvCTzgZBnU3lipZLkMzurBWgMA1YcgEHLgBlxAWVv0hOpgzK29etKbKxLLwX1aFNrg8ZR4Vn4cbutLe
    Key value = kosta
    Data balue = £»] // Some stuff doesn't show on the website but i have the weird characters in my console.
    

    Weird thing is that on the decryption output if i change QCA::Cypher::DefaultPadding i get nothing and with NoPadding i get �v-P����2��a�R]l.com � � you can notice the l.com with is obviously a part of my email address. Would you have an idea on how to fix this ? If you do not want to waste your time but you do know where to find useful documentation i would love to see it!

    [EDIT]
    Just a quick edit to say that i already tried and yes aes256 is working

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      First thing to do: use only QByteArrays, QString stores data in UTF-16 so you are doing useless and maybe disruptive conversions.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        First thing to do: use only QByteArrays, QString stores data in UTF-16 so you are doing useless and maybe disruptive conversions.

        K Offline
        K Offline
        Kosta
        wrote on last edited by
        #3

        @SGaist The problem is, when i try to input QByteArray to my data base without any type cast, nothing appears in my db and when i do typecast to QString i get some weird text popping out and some empty fields

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Since I don't know how you are communicating with your database nor how it's setup I can't help more.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved