For a small C++/Qt-application I would like to store data crypted in an SQLite-database with SQLCipher-extension.
The key, which was used to crypt the database, has to be known by the C++/Qt-application, e.g.:
...
q.exec("PRAGMA key = 'mysecretkey';");
...
As this string in the binary file is easily readable using a hex-editor, I wrote a small method which creates the key from a hash-value at runtime:
...
q.exec("PRAGMA key='" + getKey().toHex() + "';");
...
QByteArray getKey() {
...
}
With this method the key is no longer part of the binary file, but still exists in the RAM at the time of executing the method which queries the database. When the method is finished, the key is also no longer visible in the RAM.
Can you help with an idea how to avoid the key being visible in the RAM? Or do you recommend a totally different way on the basis of C++/Qt and SQLite/SQLCipher-database to solve the problem of hiding the key properly?
Amendment: The program shall enable the user to check whether a search term is part of the database or not. But the user shall not be allowed to see the database in full.