数据库
首页 > 数据库> > sqlite数据库的加密与解密

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

标签:sqlite,Lexicon,加密,encrypted,db,解密,WH,sqlcipher
来源: https://blog.csdn.net/xy1213236113/article/details/116785635