加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Using SQLCipher to encrypt sqlite db (for iOS)

发布时间:2020-12-12 20:14:04 所属栏目:百科 来源:网络整理
导读:1. Follow the steps in http://sqlcipher.net/ios-tutorial/ Hints: * DELETE existing sqlite3.* from your source code tree if you were using sqlite code earlier (very likely). SqlCipher is kind of a port from standard sqlite3,so they cannot e
1. Follow the steps in http://sqlcipher.net/ios-tutorial/ Hints: * DELETE existing sqlite3.* from your source code tree if you were using sqlite code earlier (very likely). SqlCipher is kind of a port from standard sqlite3,so they cannot exist at the same time (they have roughly the same interfaces) * The line " and add "sqlcipher" as a search path"in the tutorial means adding the path for "sqlcipher" project
That's pretty much for the 1st step. u r good to go. 2. Create SqlCipher commandline tool Somehow my previous db cannot be used by sqlcipher. It seems there is no GUI enabled tool for sqcipher. So we need to use command line. Go to sqlcipher source and run the following commands: ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" make You'll find sqlite3 in your current path. This is the "cipher-enabled" sqlite3,not the default "non-cipher-enabled" sqlite3. So you must run './sqlite xxx.db' to use this one. 3. (Dummy way to exportmy previous db to encyrpted db) My previous db was created by SQLite Database Brower 2.0. Somehow it doesn't work with sqlcipher after I tried encrypting it. Maybe there are other tricks I don't know,but I don't really care. Let's do it in a dummy way: - In SQLite Database brower,open db file,select File->Export->Database to SQL file. Save it as sql. - in sqlcipher path,run: ./sqlite3 data.db - You need to create an encrypted EMPTY database first. run: PRAGMA key='YOUR_PASS'; PRAGMA cipher='aes-256-cfb'; // by default,it's aes-256-cbc. not much difference. just don't want to use default value .q - open the db again (./sqlite data.db) - PRAGMA key='YOUR_PASS'; PRAGMA cipher='aes-256-cfb'; - run: .read database.sql .q - open the db,now u must use key/cipher to decrypt first. Now back to XCode,you need to use sqlite3_exec(...) to specify the aes mode before running any sql statements. * Note: The F***ing SQLCipher has problem handling armv7/armv7s correctly. On my iPhone4,it will use armv7 setting,but the main project will use armv7s,then it complains "undefined symbol for xxxx". As mentioned in: https://github.com/sqlcipher/sqlcipher/issues/44 http://stackoverflow.com/questions/13153439/ios-sqlcipher-sqlite-simulator-ok-deploy-on-device-error
Removing armv7s in the main project makes it working. Well,it only matters when debugging on real device. I can still unplug my iphone and choose "Archive" to publish to App Store without modifying the Architecture setting . We can just remove "armv7s" for debug build,and leave everything else alone.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读