sqlite数据库的加密与解密

sqlite数据库的加密与解密

单词创建的数据库:WH_Lexicon.db
利用sqlcipher对数据库进行加密;sqlcipher工具地址
下载之后,编译

$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto -L/usr/local/opt/openssl/lib" CPPFLAGS="-I/usr/local/opt/openssl/include"
$ make

利用sqlcipher加密 WH_Lexicon.db,秘钥:wanhe

$ sqlcipher WubiWords.db
sqlite> ATTACH DATABASE 'encrypted_WH_Lexicon.db' AS WH_Lexicon KEY 'wanhe';
sqlite> SELECT sqlcipher_export('WH_Lexicon');
sqlite> DETACH DATABASE WH_Lexicon;
sqlite> .exit

利用sqlcipher解密 encrypted_WH_Lexicon.db,秘钥:wanhe

$ ./sqlcipher encrypted_WH_Lexicon.db
sqlite> PRAGMA key = 'wanhe';
sqlite> ATTACH DATABASE 'encrypted_WH_Lexicon.db' AS WH_Lexicon KEY ''; 
sqlite> SELECT sqlcipher_export('WH_Lexicon');
sqlite> DETACH DATABASE WH_Lexicon;
sqlite> .exit

移动端解密数据库
android端
参考:https://github.com/sqlcipher/android-database-sqlcipher
文档:https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
ios端
参考项目:https://github.com/project-imas/encrypted-core-data
参考项目:https://github.com/OuDuShu/SQLCipherDemo

上一篇:QT实现对文件的Base64加解密


下一篇:一个普通的体育摄影,竟让被他玩成了这样!太惊艳了!