| asier to setup, saving many steps in project configuration pre-built with a modern version of OpenSSL, avoiding another external dependency much faster for each build cycle because the library doesn‘t need to be built from scratch on each compile (build time can be up to 95% faster with the static libraries) |
- NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
- stringByAppendingPathComponent: @"cipher.db"];
- sqlite3 *db;
- if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {
- const char* key = [@"BIGSecret" UTF8String];
- sqlite3_key(db, key, strlen(key));
- int result = sqlite3_exec(db, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL);
- if (result == SQLITE_OK) {
- NSLog(@"password is correct, or, database has been initialized");
- } else {
- NSLog(@"incorrect password! errCode:%d",result);
- }
- sqlite3_close(db);
- }
- $ ./sqlcipher plaintext.db
- sqlite> ATTACH DATABASE ‘encrypted.db‘ AS encrypted KEY ‘testkey‘;
- sqlite> SELECT sqlcipher_export(‘encrypted‘);
- sqlite> DETACH DATABASE encrypted;
- $ ./sqlcipher encrypted.db
- sqlite> PRAGMA key = ‘testkey‘;
- sqlite> ATTACH DATABASE ‘plaintext.db‘ AS plaintext KEY ‘‘; -- empty key will disable encryption
- sqlite> SELECT sqlcipher_export(‘plaintext‘);
- sqlite> DETACH DATABASE plaintext;
加密你的SQLite
标签:
本文系统来源:http://www.cnblogs.com/ligun123/p/5206942.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!