Skip to content

Commit d203343

Browse files
committed
Document SQLCipher in README
1 parent 3a5cfb5 commit d203343

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,47 @@ NDK support
308308
Just Make sure you are using the full path of your database file :
309309
`sqlite::database db("/data/data/com.your.package/dbfile.db")`.
310310

311+
SQLCipher
312+
----
313+
314+
The library has native support for [SQLCipher](https://www.zetetic.net/sqlcipher/). If you want to use encrypted databases, you have to include the `sqlite_moder_cpp/sqlcipher.h` header.
315+
Then you can create a `sqlcipher_database`.
316+
317+
```c++
318+
#include<iostream>
319+
#include <sqlite_modern_cpp/sqlcipher.h>
320+
using namespace sqlite;
321+
using namespace std;
322+
323+
int main() {
324+
325+
try {
326+
// creates a database file 'dbfile.db' if it does not exists with password 'secret'
327+
sqlcipher_config config;
328+
config.key = secret;
329+
sqlcipher_database db("dbfile.db", config);
330+
331+
// executes the query and creates a 'user' table
332+
db <<
333+
"create table if not exists user ("
334+
" _id integer primary key autoincrement not null,"
335+
" age int,"
336+
" name text,"
337+
" weight real"
338+
");";
339+
340+
// More queries
341+
342+
db.rekey("new_secret"); // Change the password of the already encrypted database.
343+
344+
// Even more queries
345+
}
346+
catch (exception& e) {
347+
cout << e.what() << endl;
348+
}
349+
}
350+
```
351+
311352
Building and Installing
312353
----
313354

0 commit comments

Comments
 (0)