PDA

View Full Version : How to create lock on .ini using QSetting?



npatil15
10th April 2020, 08:10
Hello,

I have created a .ini file but want to lock this file so that the user cannot change it manually.

give me your suggestions or let me know what other solutions to lock the .ini file

Thanks

d_stranz
10th April 2020, 17:19
My suggestions are to:

1 - Zip the file with encryption. Read the encrypted file into memory, decrypt it, and then read from the decrypted string; reverse the operations to write it - or -
2 - Leave the file itself unencrypted, but encrypt the strings in it.

Option 1 will involve writing your own QSettings format. Years ago I posted code here (https://www.qtcentre.org/threads/59733-QMetaType-dynamic-object-creation-and-initialization) for an implementation of QSettings which used XML instead of INI format. You might be able to adapt that for reading settings from an in-memory string.

Option 2 probably will require you to convert the INI string into a QByteArray, encrypt that into another QByteArray, and then use the standard QSettings class to write that out. The user will see the strings in the INI file, but if you encrypt both keys and values, they will be nonsense and not retrievable.