我想使用 sqlcipher 加密一个数据库。
我已经完成了openssl和sqlcipher的集成,构建工作非常完美。
但我的问题是我无法加密我的数据库。我不知道如何执行活动或方法来使用sql cipher加密数据库。
我在上面读到 SQL密码 但我无法理解同样的过程。我试过他们提供的代码,但不工作。
EDIT: 任何一个人可以告诉我如何设置PRAGMA密钥相同,然后如何开始与加密?因为只有这部分是剩下我的加密得到完成。
请帮助我从这种情况。
先谢谢你
使用SQLCipher要确保你有一个全新的SQLite数据库。在数据库已经有数据的情况下,出于某种原因,试图用密钥对数据库进行pragma,只是试图解密它。
这里有一些额外的信息 与现有的SQLite数据库一起工作 或 此处. 在这个例子中,encrypted.db就是你创建的那个全新的数据库和pragma。
ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret'; -- create a new encrypted database
CREATE TABLE encrypted.t1(a,b); -- recreate the schema in the new database (you can inspect all objects using SELECT * FROM sqlite_master)
INSERT INTO encrypted.t1 SELECT * FROM t1; -- copy data from the existing tables to the new tables in the encrypted database
DETACH DATABASE encrypted;