Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. XML file Encryption/Protection
Forum Updated to NodeBB v4.3 + New Features

XML file Encryption/Protection

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 6 Posters 1.6k Views 3 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.
  • faiszalkhanF Offline
    faiszalkhanF Offline
    faiszalkhan
    wrote on last edited by
    #4

    I have not given a thought to binary data. Also, please think of the file as a project file which is created by the user via the application. This file would be stored on the disk(Any location). Think of .docx file, if we open it in notepad++, we cannot make anything out of it but works perfectly with Word.

    Thanks.

    mrjjM VRoninV 2 Replies Last reply
    0
    • faiszalkhanF faiszalkhan

      I have not given a thought to binary data. Also, please think of the file as a project file which is created by the user via the application. This file would be stored on the disk(Any location). Think of .docx file, if we open it in notepad++, we cannot make anything out of it but works perfectly with Word.

      Thanks.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @faiszalkhan
      Hi
      But how much protected?
      How good are your avg. users?

      For some use cases, simply encode it with base 64 is enough to
      make it unreadable for them whereas for others user not even
      a binary file will stop them.

      You could also add a checksum to the file so you can detect if indeed changed. ( and stop loading it)

      1 Reply Last reply
      4
      • faiszalkhanF faiszalkhan

        I have not given a thought to binary data. Also, please think of the file as a project file which is created by the user via the application. This file would be stored on the disk(Any location). Think of .docx file, if we open it in notepad++, we cannot make anything out of it but works perfectly with Word.

        Thanks.

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #6

        @faiszalkhan said in XML file Encryption/Protection:

        Think of .docx file, if we open it in notepad++, we cannot make anything out of it but works perfectly with Word.

        Try opening it with 7zip (or any other zip reader). office (both MS and Open/Libre) use the first method I mentioned i.e. compress the file on save

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4
        • faiszalkhanF Offline
          faiszalkhanF Offline
          faiszalkhan
          wrote on last edited by
          #7

          @beecksche @VRonin @mrjj

          So as per the thread, I can use the following methods to protect the project file from getting changed by an average user. The Average user is a Software developer who might get the motivation to play with it.

          1. Project Data as Binary Data (Not sure about this)

          2. Compress the file on save(Need to know what are the best ways to achieve this)

          3. openssl or crypto++ to encrypt

          4. Encoding with base64

          Since I am not an expert on this and have not worked on a task of this nature before, I am not sure which option is the best to go with.

          I have two basic requirements,

          • When the user double clicks the project file, it opens in the Application, Everything is good. This is Achieved.

          • When the user tries to edit the file from outside(Say notepad++), he/she should see obfuscated data just like when Word document is opened in Notepad++. This is pending.

          Thanks.

          VRoninV 1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #8

            Is there a reason for such a requirement? Why should an user want to edit the project file manually? And if an user would do this - what is the problem? At the end he/she can edit it in your app anyway, right? As an user I would not like if the app I'm using would try to hide the data from me...
            Word files are not really obfuscated: they are zip archives containing text, images,...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            faiszalkhanF Pablo J. RoginaP 2 Replies Last reply
            0
            • jsulmJ jsulm

              Is there a reason for such a requirement? Why should an user want to edit the project file manually? And if an user would do this - what is the problem? At the end he/she can edit it in your app anyway, right? As an user I would not like if the app I'm using would try to hide the data from me...
              Word files are not really obfuscated: they are zip archives containing text, images,...

              faiszalkhanF Offline
              faiszalkhanF Offline
              faiszalkhan
              wrote on last edited by
              #9

              @jsulm There is a problem with the user editing it. The user doesn't know the exact structure of the project file, changing it might make the file not readable by the application. This could result in loss of work for the user.

              jsulmJ 1 Reply Last reply
              0
              • faiszalkhanF faiszalkhan

                @jsulm There is a problem with the user editing it. The user doesn't know the exact structure of the project file, changing it might make the file not readable by the application. This could result in loss of work for the user.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @faiszalkhan That's clear, but why would a user want to edit this file outside of your app?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • faiszalkhanF faiszalkhan

                  @beecksche @VRonin @mrjj

                  So as per the thread, I can use the following methods to protect the project file from getting changed by an average user. The Average user is a Software developer who might get the motivation to play with it.

                  1. Project Data as Binary Data (Not sure about this)

                  2. Compress the file on save(Need to know what are the best ways to achieve this)

                  3. openssl or crypto++ to encrypt

                  4. Encoding with base64

                  Since I am not an expert on this and have not worked on a task of this nature before, I am not sure which option is the best to go with.

                  I have two basic requirements,

                  • When the user double clicks the project file, it opens in the Application, Everything is good. This is Achieved.

                  • When the user tries to edit the file from outside(Say notepad++), he/she should see obfuscated data just like when Word document is opened in Notepad++. This is pending.

                  Thanks.

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #11

                  @faiszalkhan
                  1 basically means ditching all the code you already wrote to save/load in xml and start from scratch using binary data (pro: fastest serialisation/deserialisation; cons: require re-engineering the serialization process, strings serialised to binary are still pretty readable if opened in a text editor)
                  2 is a 2 stage process (pro: obfuscates the contents, doesn't require change of existing code to serialise, smaller file size. cons: slower save/load process)

                  // instead of saving directly to file, save the xml to a temporary buffer in memory
                  QByteArray plainxml;
                  QBuffer planxmldevice(&plainxml);
                  // save as usual
                  // void saveProjectFile(QIODevice* out);
                  saveProjectFile(&planxmldevice);
                  // save the compressed buffer to the final file
                  QSaveFile projectFile("projectFile.myextension");
                  Q_ASSUME(projectFile.open(QFile::WriteOnly));
                  projectFile.write(qCompress(plainxml));
                  projectFile.commit();
                  
                  // Load the compressed file and read it to a temporary buffer in memory
                  QFile projectFile("projectFile.myextension");
                  Q_ASSUME(projectFile.open(QFile::ReadOnly));
                  QByteArray compressedxml = projectFile.readAll();
                  // decompress the buffer
                  QByteArray plainxml = qUncompress(compressedxml);
                  compressedxml.clear();
                  QBuffer planxmldevice(&plainxml);
                  // void loadProjectFile(QIODevice* in);
                  loadProjectFile(&planxmldevice);
                  

                  3 is basically the same as 2 but instead of qCompress/qUncompress you'll have a function to encrypt and one to decrypt the data. The actual body of the function depends on the library and encryption method you chose (pro: encrypt the contents, doesn't require change of existing code to serialise, cons: slowerest save/load process, encryption is not hack proof)
                  4 can be used as 2 just by replacing projectFile.write(qCompress(plainxml)); with projectFile.write(plainxml.toBase64()); and QByteArray plainxml = qUncompress(compressedxml); with QByteArray plainxml = QByteArray::fromBase64(compressedxml); (pro: obfuscates the contents, doesn't require change of existing code to serialise. cons: the result will be a string of ascii chars that can still be readable and easily de-obfuscated by the user, base64 is very recognisable when opening the file with a text editor)

                  changing it might make the file not readable by the application

                  There's nothing that can prevent this to happen. The user can always mess with the content of the file with an hex editor and you just can't prevent it. All you can do is put redundancy in place (like MS office does with autorecover but as you might be aware if you ever used that feature is not 100% reliable)

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  3
                  • faiszalkhanF Offline
                    faiszalkhanF Offline
                    faiszalkhan
                    wrote on last edited by
                    #12

                    @jsulm I don't know. We've had experiences before :D
                    Thanks.

                    @VRonin Thanks. Will look into this.

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      Is there a reason for such a requirement? Why should an user want to edit the project file manually? And if an user would do this - what is the problem? At the end he/she can edit it in your app anyway, right? As an user I would not like if the app I'm using would try to hide the data from me...
                      Word files are not really obfuscated: they are zip archives containing text, images,...

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by Pablo J. Rogina
                      #13

                      As @jsulm said:

                      Why should an user want to edit the project file manually? And if an user would do this - what is the problem? At the end he/she can edit it in your app anyway

                      I'm thinking of translation files (.ts) or GUI files (.ui) in Qt itself. They're just plain XML files, and I create/edit them with proper applications (Linguist and Designer respectively). BUT I can also edit them with my favorite text editor, why not?
                      And if I mess them up, my favorite version control system (git, SVN, you name it) will come to the rescue to back them up to the point before the issue.

                      It looks like you're doing a lot of work/effort for something that could be avoided...

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      1

                      • Login

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