Basic structure program to cipher database with AES 128 to read and write #97
-
Hello, I did my basic structure program in order to cipher my database with AES 128 to read and write:
I run my program and seems all works fine. Thinking in this requirement: "Cipher your SQLite database with AES 128 for read and write". My question is: this basic structure program accomplish the requirement? I appreciate a lot your help, thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
The cipher configuration step is only necessary, if
For an already existing database (either unencrypted or encrypted) the return code of function Whether the given key is correct for an existing database will not be known, until the database is actually accessed (using some SQL statements). This follows the usual SQLite philosophy to only access the underlying database file when data are actually read or written. However, for a new empty database the given key will be used to encrypt the database file.
No, you will have to distinguish several use cases:
|
Beta Was this translation helpful? Give feedback.
-
Hi @utelle , thank you very much, I am learning and it is more clear to me how I should proceed base on your use cases. In particular, for my problem, there is a script (Command-line arguments) that previously always create a database if it doesn't exist. Then, the case new empty database is not possible in my C API environment. Therefore:
Then my question is: how can I determine correctly if the database is already encrypted or not? I have tried with the function sqlite3mc_codec_data, but I always get NULL (I have encrypted previously the database successfully). Let me show you my program.
Again, thanks a lot for the help! |
Beta Was this translation helpful? Give feedback.
-
I'm going to convert this issue into a discussion, because this is not an issue in the component itself, but in using the component.
Ok. That is, the database file that should be handled by your application already exists (and probably already has some data content), but you don't know whether it is already encrypted or not. If it is a plain unencrypted database, you want to apply encryption. If the database file is already encrypted, you want to do nothing. Is that correct? If yes, the simple approach will be to perform the following steps:
SQLite does not provide a dedicated function for checking whether a database file is encrypted or not or is a database file at all. Instead SQLite reports an error when the database is actually accessed for the first time in a session, if the database could not be accessed successfully. The return code for the unsuccessful command will usually be 26 = SQLITE_NOTADB = "Not a database file". If
Function
As explained above this will not work as expected.
No, this select command will always work, even if the wrong key was given, because it does not access the database itself, but only the library. One command, that allows to actually access the database without knowing the database schema, would be for example |
Beta Was this translation helpful? Give feedback.
I'm going to convert this issue into a discussion, because this is not an issue in the component itself, but in using the component.
Ok. That is, the database file that should be handled by your application already exists (and probably already has some data content), but you don't know whether it is already encrypted or not. If it is a plain unencrypted database, you want to apply encryption. …